在数组中获取wordpress自定义帖子类型的metabox值


Getting wordpress custom post type metabox values in the array

我已经在wordpress主题中创建了"Portfolio"自定义帖子类型。

<?php
    add_action( 'init', 'portfolio' );
    function portfolio() {
      $labels = array(
        'name' => _x('portfolio', 'post type general name'),
        'singular_name' => _x('portfolio', 'post type singular name'),
        'add_new' => _x('Add New', 'Slide'),
        'add_new_item' => __('Add New slide'),
        'edit_item' => __('Edit project'),
        'new_item' => __('New project'),
        'view_item' => __('View project'),
        'search_items' => __('Search project'),
        'not_found' =>  __('No project Found'),
        'not_found_in_trash' => __('No project found in Trash'),
        'parent_item_colon' => ''
      );
    $supports = array( 'title','editor','thumbnail');
      register_post_type( 'portfolio', 
        array(
          'labels' => $labels,
          'public' => false,
          'publicly_queryable'          =>false,
          'show_ui'         =>true,
          'show_in_menu'        =>true,
          'query_var'           =>true,
          'rewrite'         =>false,
          'capability_type'             =>'post',
          'has_archive'         =>false,
          'hierarchical'        =>false,
          'menu_position'       =>15,
          'supports' => $supports
        )
      );
    }

    ?>

在其中成功地添加了一个带有文本输入的metabox,以获取portfolio-image的URL。通过这种方式,在metabox中添加了5个具有portfolio-image url的帖子。此值的输出为<?php echo get_post_meta($post->ID,'portfolio-url',true); ?>

我已经创建了5个投资组合,每个投资组合url。如何获得数组内所有url的值,以便我可以使用jquery中的这些值作为变量?

var _portfolioImage = [url1,url2,url3,url4,url5];

<script>
var arr = new Array();
/*loop starts here*/
for(i=0;i<5;i++){
     arr.push('<?php echo get_post_meta($post->ID,'portfolio-url',true); ?>');
/*loop ends here*/
}
</script>