[英]How can I make this code search only for posts and not pages? (wp_query)
This is the code: 这是代码:
<?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;?>
For some reason it shows both posts and pages in the results page. 由于某种原因,它在结果页面中同时显示帖子和页面。 How can i exclude pages and show only posts?
如何排除页面并仅显示帖子?
I tried this but it's not working: 我试过了,但是没有用:
<?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;?>
Please help is kinda urgent. 请帮助有点紧急。 I would really appreciate it.
我真的很感激。
Add a post type to your query. 在您的查询中添加帖子类型。
http://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters 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;?>
I changed your first code 我更改了您的第一个代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.