我有一个使用ajax请求的代码加载帖子的标题。 它的工作原理如下: - 从月份和类别列表中选择 - 活动"改变"上传列表
我正在使用此说明http://wp-kama.ru/id_652/dinamicheskiy-arhiv-bloga-s-ispolzovaniem-jquery-ajax.html
显示标题帖子和时间。 我想要显示内容帖子。 我尝试get_post($ id);,但不行。
$id = 11914;// Обязательно передавать переменную
$post = get_post($id);
$content = $post->post_content;
if (have_posts()) {
echo "<tr><td>$content</td></tr>";
}
请问我,我做错了什么?
答案 0 :(得分:0)
ajax的语法是
$.post( "test.php", { name: "John", time: "2pm" })
.done(function( data ) {
alert( "Data Loaded: " + data );
});
其中test.php
- 您的网址,然后{ name: "John", time: "2pm" }
- 发送的参数,以及回调 - 您已返回结果(data
是服务器的结果)。
在php post params中有$ _POST ['%%% key_of_parameter %%%']
例如,在上面的代码中,在$_POST['name'] == "John";
(如果我理解你的问题)
P.S。 Тутнеособорасположеныкгайдамнарусском,бро)
答案 1 :(得分:0)
由于 我找到了解决方案 在test.php中我写道:
$post_id = 8994;
$queried_post = get_post($post_id);
$content = $queried_post->post_content;
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
echo $content;
我的ajax请求返回帖子号8964的内容