[英]add function to functions.php
jQuery(function($){ jQuery(函数($){
$.ajax({
url: adminAjax,
type : "POST",
data: {
action: 'get_my_post',
animal: 'animal',
sport: 'sport',
technologie: 'technologie',
celebrity: 'celebrity'
},
success: function( data ) {
$("#animalpost").html(data);
}
})
this function return a query result from a function in functions.php when i add a condition :当我添加条件时,此函数从functions.php 中的函数返回查询结果:
if(is_page("test.php")) if(is_page("test.php"))
the query ne returned nothing more please help me to fixe that查询 ne 没有返回更多信息,请帮我解决这个问题
add_action( 'wp_ajax_get_my_post', 'myfunction' );
add_action( 'wp_ajax_nopriv_get_my_post', 'myfunction' );
function myfunction() {
if ( isset( $_POST['animal'] ))
{
if(is_page( 'test' ) )
{
$args = array( 'post_type' => 'journals'
); $journal = new WP_Query( $args ); if( $journal->have_posts() ):
jQuery.ajax({
url: "<?php echo get_admin_url(); ?>admin-ajax.php",
type : "POST",
data: {
action: 'get_my_post',
animal: 'animal',
sport: 'sport',
technologie: 'technologie',
celebrity: 'celebrity'
},
success: function( data ) {
jQuery("#animalpost").html(data);
}
})
Use this instead of your..hopefully it works :)用它代替你的..希望它有效:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.