我需要在ajax函数中加载一个选定的帖子,我在编写调用我指向的帖子的相应查询时遇到了一些问题
<?php
$pb_id = $_POST['post_id'];
$pb_details_args = array(
'p' => $pb_id,
);
$pb_details_query = new WP_Query( $pb_details_args );
while ($pb_details_query -> have_post() ):
$pb_details_query -> the_post();
echo '<h4>' . get_the_title() . '</h4>';
endwhile
?>
目前我有这段代码,但我认为基本上完全错了,你能帮助我吗?
答案 0 :(得分:1)
如果你只需要头衔,你可以选择:
<?php
echo get_the_title($_POST['post_id']);
?>
这会给你jsut帖子标题。如果你需要其他一切:
<?php
$single_post = get_post( $_POST['post_id'] );
echo $single_post->post_title; // title
?>
完整参考:
WP_Post Object
(
[ID] =>
[post_author] =>
[post_date] =>
[post_date_gmt] =>
[post_content] =>
[post_title] =>
[post_excerpt] =>
[post_status] =>
[comment_status] =>
[ping_status] =>
[post_password] =>
[post_name] =>
[to_ping] =>
[pinged] =>
[post_modified] =>
[post_modified_gmt] =>
[post_content_filtered] =>
[post_parent] =>
[guid] =>
[menu_order] =>
[post_type] =>
[post_mime_type] =>
[comment_count] =>
[filter] =>
)