php – WordPress:’post_name’上的WP_Query搜索条件

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了php – WordPress:’post_name’上的WP_Query搜索条件脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在使用WP_Query(非常标准).一切都很好.

但是,我做了一个特别的修改,其中,如果用户在URL中输入特定的帖子名称,搜索将只返回匹配该post_name值的帖子.

请参阅下面的代码,其中包含有关特定行无效的注释.

<?PHP

$getPEople = array(
    'post_type' => 'person','posts_per_page' => -1,// I want this below to only return me the post wITh this specific value.
    // This doesn't error,but doesn't work either.
    // I kNow it seems counter-PRoductive to a 'seArch' but this particular case requires it.
    // This has a hard-coded value at the moment.
    'post_name' => 'rebecca-atkinson','orderby' => 'Meta_value','Meta_key' => 'last-name','order' => 'ASC','Meta_query' => array(
        array(
            'key' => 'gender','value' => $theGender,)
    ),'tax_query' => array(

        'relation' => 'OR',array(
            'taxonomy' => 'accent','field' => 'slug','terms' => $theAccent,'operator' => 'IN',),array(
            'taxonomy' => 'style','terms' => $theStyle,array(
            'taxonomy' => 'age','terms' => $theAge,)
);

$myposts = new WP_Query($getPeople);

?>

非常感谢您的帮助.如果我能看到如何搜索这个特定的’slug’,那就太棒了.

非常感谢,
迈克尔.

代替
'post_name' => 'rebecca-atkinson',

使用:

'name' => 'rebecca-atkinson',

脚本宝典总结

以上是脚本宝典为你收集整理的php – WordPress:’post_name’上的WP_Query搜索条件全部内容,希望文章能够帮你解决php – WordPress:’post_name’上的WP_Query搜索条件所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。