这是代码:
<?php global $wp_query;
$search_term=$_REQUEST['search-terms'];
if(empty($search_term))
$search_term=$_REQUEST['s'];
$wp_query->query("s=".$search_term);?>
<?php if ( have_posts() ) : ?>
<?php while(have_posts()):the_post(); global $post;?>
由于某种原因,它会在结果页面中显示帖子和页面。如何排除页面并仅显示帖子?
我尝试了这个,但它不起作用:
<?php global $wp_query;
$args = array_merge( $wp_query->query, array( 'post_type' => 'post' ) );
query_posts( $args );
$search_term=$_REQUEST['search-terms'];
if(empty($search_term))
$search_term=$_REQUEST['s'];
$wp_query->query("s=".$search_term);?>
<?php if ( have_posts() ) : ?>
<?php while(have_posts()):the_post(); global $post;?>
请帮忙有点紧急。我真的很感激。
答案 0 :(得分:1)
在查询中添加帖子类型。
http://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters
<?php global $wp_query;
$search_term=$_REQUEST['search-terms'];
if(empty($search_term))
$search_term=$_REQUEST['s'];
$wp_query->query("post_type=post&s=".$search_term); ?>
<?php if ( have_posts() ) : ?>
<?php while(have_posts()):the_post(); global $post;?>
我更改了您的第一个代码