[英]How can I make this code search only for posts and not pages? (wp_query)
這是代碼:
<?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;?>
請幫助有點緊急。 我真的很感激。
在您的查詢中添加帖子類型。
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;?>
我更改了您的第一個代碼
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.