简体   繁体   English

Redux框架,Wordpress,从所有帖子类型中选择页面/帖子

[英]Redux framework, Wordpress, Select page/post from all post types

I'm using Redux and I want select one post/page form select list. 我正在使用Redux,我想选择一个帖子/页面表单选择列表。 But I want choose form some post types (or all). 但是我想选择一些帖子类型(或全部)。 This is my Redux code for this field. 这是我针对此字段的Redux代码。

        'fields'     => array(
            array(
                'id'       => 'featured_post_type',
                'type'     => 'select',
                'multi'    => false,
                'data'      => 'pages',
                'args' => array('post_type' => array('nyheter_grenene', 'nyheter_forbundet', 'stup') ),
                'title'    => __('Featured Post', TD),
                'subtitle' => __('Selected post will be displayed in page top menu', TD),
                //'desc'     => __('Page will be marked as front for this post type', TD),
            ),
       ),

There are two things that you have to change in your code so that it works properly. 为了使代码正常工作,您必须更改两件事。 Here's a working version: 这是一个工作版本:

'fields'     => array(
    array(
        'id'       => 'featured_post_type',
        'type'     => 'select',
        'multi'    => false,
        'data'     => 'posts',
        'args'     => array( 'post_type' =>  array( 'nyheter_grenene', 'nyheter_forbundet', 'stup' ), 'numberposts' => -1 ),
        'title'    => __( 'Featured Post', TD ),
        'subtitle' => __( 'Selected post will be displayed in page top menu', TD ),
        //'desc'     => __( 'Page will be marked as front for this post type', TD ),
    ),
),

The difference here is that we have 'data' => 'posts' (instead of pages ) and we also added 'numberposts' => -1 to the args array. 此处的区别在于,我们有'data' => 'posts' (而不是pages ),并且还向args数组添加了'numberposts' => -1

When you use 'data' => 'pages' , the function [get_pages()][1] is used, which only supports hierarchical post types. 当您使用'data' => 'pages' ,将使用函数[get_pages()][1] ,该函数仅支持分层文章类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM