gpt4 book ai didi

mysql - Wp_query 在 WordPress 中不起作用?

转载 作者:行者123 更新时间:2023-11-29 20:53:25 25 4
gpt4 key购买 nike

我是 WordPress 新手,我无法理解 WordPress 中的 WP_Query,我传递参数 post_status => 'public' 意味着 WordPress 中发生了什么,

select * from wp_posts where post_status ='public'

我想编写查询并显示像上面 mysql_query 这样的详细信息。但是在我的 WordPress 编码下面,其获取结果 post_status ='auto_craft',我很困惑为什么它显示该结果,但我传递了 post_status ='public'

WordPress:

<?php
$args = array(
'posts_per_page' => -1,
'post_status' => 'public'
);
$post_query = null;
$post_query = new WP_Query($args);
var_dump($post_query->request);



if ($post_query) {

while ($post_query->have_posts()) : $post_query->the_post();
echo "fdsfl;dslfgsss";
global $post;
echo $post->post_title;



endwhile;
wp_reset_query();
}
?>

我上面的代码有什么问题吗?在我的 var_dump 中,我得到如下结果,

"SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'post' ORDER BY wp_posts.post_date DESC " 

1 = 1 是什么?不检查 'post_status' = 'public'

我的自定义编码:

$post_status = empty($postarr['post_status']) ? 'draft' : $postarr['post_status'];
if ('attachment' === $post_type && in_array($post_status, array('public'))) {
$post_status = $postarr['post_status'];
} elseif ('attachment' === $post_type && in_array($post_status, array('private_soundcloud'))) {
$post_status = 'private_soundcloud';
} else {
if ('attachment' === $post_type && !in_array($post_status, array('inherit', 'private', 'trash'))) {
$post_status = 'inherit';
}
}

最佳答案

您必须传递错误的post_status值,请替换为

'post_status' => 'public'

'post_status' => 'publish'

关于mysql - Wp_query 在 WordPress 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37833141/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com