从URL获取帖子ID在WordPress
答
数据要想从
GET
参数,您可以使用filter_input()
,或WordPress的get_query_var()
方法的价值。在获得ID后,您可以使用WP_Query
查询帖子并获得 。
$post_id = filter_input(INPUT_GET, 'id');
if (!empty($post_id))
{
$args = [
'post_type' => 'bcworks', //<--replace it with your post_type
'p' => $post_id
];
// The Query
$the_query = new WP_Query($args);
}
else
{
//no post found
}
希望这有助于!
答
为ID使用上一个WordPress取下面的代码
<?php
// would echo post 7's content up until the <!--more--> tag
$post_7 = get_post(7);
$excerpt = $post_7->post_excerpt;
echo $excerpt
// would get post 12's entire content after which you
// can manipulate it with your own trimming preferences
$post_12 = get_post(12);
$trim_me = $post_12->post_content;
my_trim_function($trim_me);
?>
如何获得$ the_query –
的帖子标题和内容非常感谢。它效果不错 –
你能帮我过滤器搜索如名称,地址和邮政编码表格搜索 –