在 wordpress 中使用自定义字段进行搜索 [英] Search using custom fields in wordpress

查看:51
本文介绍了在 wordpress 中使用自定义字段进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正忙于使用 WordPress 开发 Web 应用程序.我创建了一个带有一些自定义字段的自定义帖子.当我使用 WordPress 搜索框搜索帖子时,只会返回标题与搜索字符串匹配的帖子.我想在搜索域上添加自定义字段.

I am busy developing a web application using WordPress. I have created a custom post with a few custom fields. When I search for post using WordPress search box only post with title that match the search string get returned. I want to add custom fields on searching domain.

我可以在 WordPress 中按自定义字段值进行搜索吗?

I there a to search by custom field values in WordPress?

推荐答案

以下可以做

$args=array(
'post_type'=>'custom post',
'order'=>'ASC',
'orderby'=>'menu_order',
'meta_query' => array (
            array (
              'key' => 'meta-key',
              'value' => 'meta-value',
            )
          )
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
    while ( $the_query->have_posts() ) {
        $the_query->the_post();
        echo the_title();

                }
} 
wp_reset_postdata();

这篇关于在 wordpress 中使用自定义字段进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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