繁体   English   中英

将函数添加到functions.php

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM