我需要帮助,因为我想从URL获得帖子ID,因为我使用
?id='1'我希望获得这个ID,并在另一个WordPress页面上获取数据。
发布于 2017-04-25 06:56:27
要从
GET参数中获取值,可以使用filter_input()或WordPressget_query_var()方法。获得ID后,可以使用WP_Query查询post。
$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
}希望这能有所帮助!
发布于 2017-04-25 06:50:20
要用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 );
?>https://stackoverflow.com/questions/43603384
复制相似问题