Ajouter une fonction a function.php

Houssine@ Messages postés 48 Statut Membre -  
Houssine@ Messages postés 48 Statut Membre -
Bonjour,
j'ai un fichier page-animal.php et script.js et functions.php.
J'ai ajouté une fonction ajax a mon script qui retourne une requête de tous les animaux et quand j'ai voulu ajouté une condition de if(is_page(page-story)) la requête ne retourne plus rien comment procéder pour ajouter cette fonction et merci d'avance

Configuration: Windows / Chrome 71.0.3578.98

1 réponse

  1. Houssine@ Messages postés 48 Statut Membre
     
    -3

    jQuery(function($){

    $.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 :

    //if(is_page("test.php"))

    //the query ne returned nothing more please help me to fixe that

    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() ):
    0