[英]Wordpress add function to functions.php that only fires on login
[英]add function to functions.php
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);
}
})
當我添加條件時,此函數從functions.php 中的函數返回查詢結果:
if(is_page("test.php"))
查詢 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);
}
})
用它代替你的..希望它有效:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.