我的wp\\U帖子中有大约46k行。我只想查询符合查询条件的数据库,并显示结果帖子,但我的问题是,我对数据库所做的任何查询都只显示添加的最后5个条目。这就是代码:
if(isset($_GET["submit"])){
$nume_searchq=$_GET["nume_doc"];
$spec_searchq=$_GET["specializare_doc"];
$instit_searchq=$_GET["spital_doc"];
?>
<hr>
<strong>Rezultatele cautarii:</strong>
</br>
<?php
$query= $wpdb->get_results("SELECT * FROM `wp_posts` WHERE post_content like \'%Alba%\' OR LOWER(post_title) LIKE \'%$nume_searchq%\' OR LOWER(post_content) LIKE \'%$spec_searchq%\' OR LOWER(post_content) LIKE \'%$instit_searchq%\' ".$limit, OBJECT);
$pageposts =get_posts($query);
if($pageposts){
foreach($pageposts as $post){
global $post;
setup_postdata($post);
echo \'<li><a href="\' . get_the_permalink() . \'"> \' . get_the_title() . \' </a></li>\';
wp_reset_postdata();
}//end_Foreach
}//end_if
?>
我尝试了不同的方法和查询,但最近的5个条目仍然显示。。。我怎样才能解决这个问题?PS:不要为$limit变量操心,因为我在这个查询下有一个分页代码。谢谢
乐:我对代码做了一些修改,我有结果,但在我的查询中i only need posts 它绝对显示数据库中的所有内容,包括小图片、联系方式、不同页面、不同代码、帖子等。目前代码如下:
<?php
switch($_GET[\'filter1\']){
case "ALL":
$querystr = "SELECT * FROM `wp_posts` WHERE post_type=\'post\' OR LOWER(post_title) LIKE \'%$nume_searchq%\' OR LOWER(post_content) LIKE \'%$spec_searchq%\' OR LOWER(post_content) LIKE \'%$instit_searchq%\' ";
break;
case "AB":
$querystr = "SELECT * FROM `wp_posts` WHERE post_content LIKE \'%Alba%\' AND post_type=\'post\' OR LOWER(post_title) LIKE \'%$nume_searchq%\' OR LOWER(post_content) LIKE \'%$spec_searchq%\' OR LOWER(post_content) LIKE \'%$instit_searchq%\' ";
break;
..... //more case`es }
$pageposts = $wpdb->get_results($querystr, OBJECT); ?>
<?php if ($pageposts): ?>
<?php foreach ($pageposts as $post): ?>
<?php setup_postdata($post); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
<?php the_title(); ?></a></h2>
<?php //display_rating_result(); ?>
<div class="entry">
<?php the_content(\'Read the rest of this entry »\'); ?>
</div>
<?php edit_post_link(\'Edit\', \'\', \' | \'); ?>
<?php comments_popup_link(\'No Comments »\', \'1 Comment »\', \'% Comments »\'); ?></p>
</div>
<?php endforeach; ?>
<?php else : ?>
<h2 class="center">Not Found</h2>
<?php endif;
}//end_submit
?>