【问题标题】:Getting wordpress custom post type metabox values in the array在数组中获取 wordpress 自定义帖子类型元框值
【发布时间】:2013-03-21 06:42:26
【问题描述】:

我在 wordpress 主题中创建了“投资组合”自定义帖子类型。

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


    ?>

在其中成功添加了一个带有文本输入的元框,以获取portfolio-image的URL。通过这种方式,添加了 5 个帖子,其中包含 metabox 中的投资组合图像 url。这个值的输出是&lt;?php echo get_post_meta($post-&gt;ID,'portfolio-url',true); ?&gt;

我创建了 5 个投资组合,每个投资组合都有投资组合网址。如何获取数组中所有 url 的值,以便我可以将 jquery 中的这些值用作变量?

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

【问题讨论】:

    标签: php custom-post-type wordpress


    【解决方案1】:

    把这个写在循环里面

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

    【讨论】:

      猜你喜欢
      • 2016-04-03
      • 2016-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-27
      • 2016-10-28
      • 1970-01-01
      • 2013-04-24
      相关资源
      最近更新 更多