Getting wordpress custom post type metabox values in the array

I have created “Portfolio” custom post type in the wordpress theme .

<?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
        )
      );
    }


    ?>

Inside it successfully added a metabox with text input to get the URL of portfolio-image. In this way 5 post added which having portfolio-image url in metabox. Output for this value is <?php echo get_post_meta($post->ID,'portfolio-url',true); ?>

Read More

I have created 5 portfolio having portfolio url for each. How can get values of all url inside array so I can use those value inside jquery as variable?

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

Related posts

Leave a Reply

1 comment

  1. Write this in a loop where

    <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>