在wordpress中使用Jquery Ajax而不在帖子页面中使用wp-load.php文件

时间:2015-07-14 07:49:10

标签: php jquery ajax wordpress

我正在使用Jquery发布值并从我的插件中的外部页面获取一些返回值,在该页面中我使用wp-load.php来访问wordpress功能。没有wp-load.php在该页面中使用我们如何获得结果, 这里是我的两个插件页面的代码。

主插件文件有Jquery。

var locations = function () {
    var tmp = null;
        $.ajax({        
        'async': false, 
        'type': "POST",
        dataType: 'json',
        url: "<?php  echo plugins_url( 'json.php', __FILE__  ); ?>",
        data: "post_type="+post_type_loc,
            success: function(data){
                 tmp = data;
            }
        });
           return tmp;
    }();

和Json页面有这样的代码。

<?php
// PHP array
include_once("../../../wp-load.php");
?>
<?php 
$products = array();
$post_type=$_POST['post_type'];
$loop = get_posts('post_type='.$post_type); ?>
<?php foreach ( $loop as $post ) : setup_postdata( $post ); ?>


 <?php endforeach;
wp_reset_postdata();
?>

如果没有使用jquery ajax和wp-load.php include来执行此操作,还有其他方法。

0 个答案:

没有答案