Ste*_*unn 10 tags wordpress search keyword
我使用get_posts获取与搜索关键字匹配的帖子列表,问题是我get_posts的s 参数默认情况下不搜索标签,tag_slug__in如果在标题中找不到关键字而不在标签中,则使用将不起作用.
我的搜索条件是:
任何想法都会很棒.我尝试了"搜索所有内容"插件,但这似乎只适用于WordPress的默认搜索功能.
下面的代码是我尝试的简化版本,而不是满足所有3个标准.
<?php
/* Set global query parameters */
$image_args = array(
    'posts_per_page' => (isset($_GET['show_all']) && $_GET['show_all'] == 'true')? 100000 : 20,
    'post_type' => 'attachment',
    'post_mime_type' => array('image/jpeg', 'image/png'),
    'meta_key' => 'language',
    'meta_value' => "(^".$languages."$|\"".$languages."\"\;)",
    'meta_compare' => 'REGEXP',
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'media_category',
            'field' => 'term_id',
            'terms' => array($gallery_filter, $hotel->term_id),
            'operator' => 'AND',
        ),
    ),
);
/* If page numbert given, add offet */
if(!empty($page_no))
    $images_args['offset'] = 20*((int)$page_no-1);
/* If search term submitted, add it to the s parameter */
if(isset($_GET['search'])){
    $image_args['tag_slug__in' = explode(" ", $_GET['search']);
    $image_args['s'] = urldecode($_GET['search_term']);
}
您可以使用您自己的查询。下面是一个例子
$querystr="
    SELECT *
        FROM $wpdb->posts, $wpdb->term_relationships, $wpdb->term_taxonomy, $wpdb->terms
            WHERE ($wpdb->terms.name = '$s'
            OR $wpdb->posts.post_content LIKE '%$s%'
        OR $wpdb->posts.post_title LIKE '%$s%')
        AND $wpdb->posts.ID = $wpdb->term_relationships.object_id
        AND $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id
        AND $wpdb->term_taxonomy.term_id = $wpdb->terms.term_id
        ORDER BY $wpdb->posts.post_date DESC
";
$pageposts = $wpdb->get_results($querystr, OBJECT_K);
foreach ($pageposts as $post): setup_postdata($post);
    echo the_title() . '<br /><br />';
endforeach;
| 归档时间: | 
 | 
| 查看次数: | 3707 次 | 
| 最近记录: |