GET_POST返回空数组

时间:2019-05-09 作者:Jobbie Daddy

我正在构建一个自定义WordPress函数/插件,它使用get\\u帖子。以下代码返回empy数组。我已包括wp负载。php在我的脚本中。我还缺什么吗?

$args = array(
    "posts_per_page"   => -1,
    "paged"            => 0,
    "orderby"          => "post_date",
    "order"            => "DESC",
    "post_type"        => "carellcars, ccf, attachment",
    "post_status"      => "publish, inherit",
    "post_author"       => "2"

);

$posts_array = get_posts($args); 

print_r($posts_array);

die;
如果对post\\U类型和状态使用数组,则不会填充数组,但如果对post\\U类型和状态使用单个值,则会填充数组?

未填充:

$args2 = array(
    \'posts_per_page\'   => -1,
    \'paged\'            => 0,
    \'orderby\'          => \'post_date\',
    \'order\'            => \'DESC\',
    \'post_type\' => array(\'carellcars\', \'ccf\', \'attachment\'),
    \'post_status\'      => array(\'publish\', \'inherit\')
);
已填充:

$args2 = array(
    \'posts_per_page\'   => -1,
    \'paged\'            => 0,
    \'orderby\'          => \'post_date\',
    \'order\'            => \'DESC\',
    \'post_type\' =>  \'carellcars\',
    \'post_status\'      => \'publish\'
);
更新,删除“ccf”post类型会产生结果,但我有一个ccf post\\u类型,并希望包含它们。有什么想法吗?

    \'post_type\' => array(\'carellcars\', \'attachment\'),
    \'post_status\'      => array(\'publish\', \'inherit\')

1 个回复
SO网友:Keith Donegan

Try

"post_type" => array(\'carellcars\', \'ccf\', \'attachment\'),

相关推荐