wordpress 首页 全文检索 条件问题

1全文检索文章分类过滤问题:

全文检索在index.php里面 使用form提交给query函数所以用php 函数设定参数无效,可以使用inut进行设定

比如对类别进行限定:
 

<input name="cat" type="hidden" value="1" /> <!--表示对cat id 为1的所在分类下的文章进行选取-->

<input name="cat" type="hidden" value="-1" /> <!--表示对cat id 为1的所在分类下的文章进行过滤-->

<input name="cat" type="hidden" value="-1,-2" /> <!--表示对cat id 为1,还有-2的所在分类下的文章进行过滤-->

2全文检索文章类型过滤问题:

<input name="post_type" type="hidden" value="post" /> <!--表示对post_type  为posts表中文章类型的内容进行选取-->

 以此类推可以根据一下参数对筛选条件进行调整,以此达到合适的需求

<?php 
$args = array(  
 
	//作者参数 - Show posts associated with certain author.
    //http://codex.wordpress.org/Class_Reference/WP_Query#Author_Parameters
    'author' => '1,2,3,',                     //(int) - use author id [use minus (-) to exclude authors by ID ex. 'author' => '-1,-2,-3,']
    'author_name' => 'luetkemj',              //(string) - use 'user_nicename' (NOT name)
    'author__in' => array( 2, 6 ),            //(array) - use author id (available with Version 3.7).
    'author__not_in' => array( 2, 6 ),        //(array)' - use author id (available with Version 3.7).
 
	//类别参数 - Show posts associated with certain categories.
    //http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
    'cat' => 5,//(int) - use category id.
    'category_name' => 'staff, news',          //(string) - Display posts that have these categories, using category slug.
    'category_name' => 'staff+news',           //(string) - Display posts that have "all" of these categories, using category slug.
    'category__and' => array( 2, 6 ),         //(array) - use category id.
    'category__in' => array( 2, 6 ),          //(array) - use category id.
    'category__not_in' => array( 2, 6 ),      //(array) - use category id.
 
	//标签参数 - Show posts associated with certain tags.
    //http://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters
    'tag' => 'cooking',                       //(string) - use tag slug.
    'tag_id' => 5,                            //(int) - use tag id.
    'tag__and' => array( 2, 6),               //(array) - use tag ids.
    'tag__in' => array( 2, 6),                //(array) - use tag ids.
    'tag__not_in' => array( 2, 6),            //(array) - use tag ids.
    'tag_slug__and' => array( 'red', 'blue'), //(array) - use tag slugs.
    'tag_slug__in' => array( 'red', 'blue'),  //(array) - use tag slugs.
 
	//分类参数(自定义分类法) - Show posts associated with certain taxonomy.
    //http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
    //Important Note: tax_query takes an array of tax query arguments arrays (it takes an array of arrays)
    //This construct allows you to query multiple taxonomies by using the relation parameter in the first (outer) array to describe the boolean relationship between the taxonomy queries.
    'tax_query' => array(                     //(array) - use taxonomy parameters (available with Version 3.1).
    'relation' => 'AND',                      //(string) - Possible values are 'AND' or 'OR' and is the equivalent of running a JOIN for each taxonomy
      array(
        'taxonomy' => 'color',                //(string) - Taxonomy.
        'field' => 'slug',                    //(string) - Select taxonomy term by ('id' or 'slug')
        'terms' => array( 'red', 'blue' ),    //(int/string/array) - Taxonomy term(s).
        'include_children' => true,           //(bool) - Whether or not to include children for hierarchical taxonomies. Defaults to true.
        'operator' => 'IN'                    //(string) - Operator to test. Possible values are 'IN', 'NOT IN', 'AND'.
      ),
      array(
        'taxonomy' => 'actor',
        'field' => 'id',
        'terms' => array( 103, 115, 206 ),
        'include_children' => false,
        'operator' => 'NOT IN'
      )
    ),
	//文章和页面参数 - Display content based on post and page parameters.
    //http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters
    'p' => 1,                               //(int) - use post id.
    'name' => 'hello-world',                //(string) - use post slug.
    'page_id' => 1,                        
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值