如何在json中获取WordPress的自定义发布数据?

问题描述:

在我的模板文件,我取自定义后的数据是这样,如何在json中获取WordPress的自定义发布数据?

enter image description here

起初我取7后,我需要做出更多按钮波纹管后,将获取从更多的7个员额wp数据库表,当有人点击它。

但我不知道该怎么做,我想了解一下,

  • jQuery的get方法,其php文件我呼吁数据,
  • 如何或什么确切的剧本我将写入该PHP文件。
+0

在function.php中创建一个ajax函数,并通过ajax调用将偏移值传递给它,并在disply区域添加接收到的数据。 – Balwant

+0

嘿兄弟,你能给出更详细的答案... @Balwant –

在这里,我已经添加了一个粗略的想法如何编写代码:

创建function.php一个AJAX功能,并通过Ajax调用传递偏移值,并只是追加在接收数据的显示部分。

这里是创建AJAX功能的例子:

add_action('wp_ajax_nopriv_cyt_ajax_search','cyt_ajax_search'); 
add_action('wp_ajax_cyt_ajax_search','cyt_ajax_search'); 
function cyt_ajax_search(){ 


    $offset = $_POST['offset']; 

    $args = array (
    'post_type' => 'post', 
    'posts_per_page' =>7 
    'offset'=>$offset, 

    'meta_query' =>.......... 

    ); 
$query = new WP_Query($args); 
if($query->have_posts()) : 
     while ($query->have_posts()) : $query->the_post(); 


endwhile; 

wp_reset_postdata(); 
endif; 


} 

//前端代码,按钮点击后将CAL的AJAX功能,并通过偏移值,每个点击你需要增加值7(如果你想只加载7后),并检查有多少职位被留下,如果偏移值exceedded无总的统计数据是由WP查询画面,然后简单地隐藏按钮

<div id ="esiSection"></div> 
 

 
<span click="loadmore" data-offset='0'>Click here</span> 
 

 
jQuery('.loadmore').click(function(){ 
 
var offset = parseInt(jQuery(this).attr('data-offset')); 
 
jQuery.ajax({ \t \t \t \t 
 
\t \t \t url: '<?php echo admin_url('admin-ajax.php'); ?>', 
 
\t \t \t type: 'POST', \t \t \t 
 
\t \t \t data: { 
 
\t \t \t \t 'action' : 'cyt_ajax_search', 
 
\t \t \t \t 'offset' : offset , 
 
\t \t \t }, 
 
\t \t success: function(response) { 
 
\t \t 
 
\t \t \t jQuery('#resiSection').append(response); 
 
\t \t \t offset = offset + 7; 
 
\t 
 
\t \t \t 
 
\t \t }, 
 
\t \t error: function(error){ 
 
\t \t \t console.log(error); 
 
\t \t \t 
 
\t \t } 
 
\t \t \t \t 
 
\t }); \t 
 
\t 
 
}); \t

+0

非常感谢你兄弟....... –

+0

不客气,欢呼! – Balwant