's' =>$term, 不是在 wordpress/php 的 post_title 的基础上拉帖子 [英] 's' => $term, is not pulling posts on the basis of post_title in wordpress/php

查看:13
本文介绍了's' =>$term, 不是在 wordpress/php 的 post_title 的基础上拉帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 php 代码,我想在其中根据 post_title 拉帖子.让我们假设 $keywordchicagoChicago.

if ($keyword) {$query = new \WP_Query(['s' =>$关键字,'post_type' =>'abc-xyz','post_status' =>'发布']);} 别的 {$query = new \WP_Query(['post_type' =>'abc-xyz','post_status' =>'发布',//'ep_integrate' =>真的,'orderby' =>'标题','订单' =>'ASC']);}echo '

';print_r($query->posts);echo '</pre>';//A线

$keywordChicagochicago 时,A 行打印以下数组:

数组([0] =>WP_Post 对象([ID] =>280045[post_title] =>芝加哥)[1] =>WP_Post 对象([ID] =>680045[post_title] =>皮奥里亚)[2] =>WP_Post 对象([ID] =>180045[post_title] =>皮奥里亚)[3] =>WP_Post 对象([ID] =>880045[post_title] =>芝加哥)[4] =>WP_Post 对象([ID] =>180000[post_title] =>芝加哥))

我想知道为什么当 $keywordchicagopost_title Peoria代码>芝加哥.

解决方案

正如@FluffyKitten 所指出的,默认的 Wordpress 搜索不仅限于帖子标题.它同时搜索 post_titlepost_content.

I have a php code in which I want to pull posts on the basis of post_title. Let us suppose the $keyword is chicago or Chicago.

if ($keyword) {
        $query = new \WP_Query([
            's' => $keyword,
            'post_type' => 'abc-xyz',
            'post_status' => 'publish'
        ]);
    } else {
        $query = new \WP_Query([
            'post_type' => 'abc-xyz',
            'post_status' => 'publish',
            //'ep_integrate' => true,
            'orderby' => 'title',
            'order' => 'ASC'
        ]);
    }
    
    echo '<pre>'; print_r($query->posts); echo '</pre>';  // Line A

Line A prints the following array when $keyword is Chicago or chicago:

Array
(
    [0] => WP_Post Object
        (
            [ID] => 280045
            [post_title] => Chicago
        )

    [1] => WP_Post Object
        (
            [ID] => 680045
            [post_title] => Peoria
        )

    [2] => WP_Post Object
        (
            [ID] => 180045
            [post_title] => Peoria
        )

    [3] => WP_Post Object
        (
            [ID] => 880045
            [post_title] => Chicago
        )

    [4] => WP_Post Object
        (
            [ID] => 180000
            [post_title] => Chicago
        )
)       
    

I am wondering why its pulling posts with the post_title Peoria when the $keyword is chicago or Chicago.

解决方案

As @FluffyKitten notes, the default Wordpress search is not limited to just the post title. It searches both post_title and post_content.

这篇关于's' =>$term, 不是在 wordpress/php 的 post_title 的基础上拉帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆