为什么在此查询中会忽略POST_TYPE?

时间:2012-03-26 作者:jnthnclrk

在下面的查询中,post\\u类型似乎被忽略,导致显示我安装的所有帖子。我做错了什么?

<?php
function filter_where( $where = \'\' ) {
    $where .= " AND post_date > \'2009-03-01\'";
    return $where;
}
add_filter( \'posts_where\', \'filter_where\' );

$posts = query_posts( \'&showposts=-1&post_type=listings\' );

remove_filter( \'posts_where\', \'filter_where\' );

echo \'<ol>\';
foreach ($posts as $post) {
    echo \'<li>\' . get_the_title() . \'</li>\';
}
echo \'</ol>\';
?>

1 个回复
最合适的回答,由SO网友:Eugene Manuilov 整理而成

检查您的post\\u类型是否准确listings 而不是listing. 还要检查这种方法:

<?php
function filter_where( $where = \'\' ) {
    $where .= " AND post_date > \'2009-03-01\'";
    return $where;
}
add_filter( \'posts_where\', \'filter_where\' );

function parse_wp_query( $query ) {
    $query->set( \'post_type\', array( \'listings\' ) );
    return $query;
}
add_filter( \'parse_query\', \'parse_wp_query\' );

$posts = query_posts( \'posts_per_page=-1&post_type=listings\' );

remove_filter( \'posts_where\', \'filter_where\' );
remove_filter( \'parse_query\', \'parse_wp_query\' );

echo \'<ol>\';
foreach ($posts as $post) {
    echo \'<li>\' . get_the_title() . \'</li>\';
}
echo \'</ol>\';
?>

结束

相关推荐

Grouping post-types in loop

当用户从下拉列表中选择特定类别时,将显示多个帖子类型的列表。我想用标题中的帖子类型标题分组显示数据。我不确定如何划分为岗位类型组。我花了一点时间寻找,但没有找到我真正需要的东西。我还试图添加<?php $post_type = get_post_type( $post->ID ); echo $post_type; ?> 但这只是重复(显然)。调用循环<div id=\"content\" role=\"main\" style=\"float:right; width:765px