wordpress - 获取 wordpress 中搜索结果的总数
问题描述
如何在wordpress的搜索结果页面中获取结果总数......我想我的问题很清楚。我需要搜索结果页面中显示的搜索结果总数。还需要找到来自页面的结果并分别发布
我尝试过的是
<?php echo count($posts); ?>
通过使用这个我得到了搜索结果的总数。但我还需要搜索结果中的页数和帖子数
解决方案
一旦您已经在搜索查询中,您也可以使用全局 $wp_query。
请参见下面的示例:
<?php
global $wp_query;
$not_singular = $wp_query->found_posts > 1 ? 'results' : 'result'; // if found posts is greater than one echo results(plural) else echo result (singular)
echo $wp_query->found_posts . " $not_singular found";
?>
推荐阅读
- java - 如何在 Java 中访问另一个文件或类上的 JButton
- python - Can someone please explain me these lines of code?
- python-3.x - Discord.py on_invite_create event
- javascript - Rectangle not showing on canvas
- c++ - 将基类的指针转换为带有模板的继承类的指针
- python - Using pd.Grouper with multiple time units (months, days)
- css - How to resize images inside a flexbox without using a background image?
- python - When I install the IRI (IOTA reference implementation), I encouter some problems
- ethereum - I need help understanding differences between Inherit via Import / Separate Contracts / Libraries+Interface
- reactjs - 同一个 ReactJS 表单中的多个逻辑分离的单选按钮