0

这是代码:

<?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;?>

请帮助有点紧急。我真的很感激。

4

1 回答 1

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;?>

我改变了你的第一个代码

于 2013-01-14T17:43:18.317 回答