0
votes

I'm working on a website and i've created a custom filter method. Every post have 2 custom ACF fields. I've set args and query and eveythings fine WHILE i'm logged in ONLY.

If I try to display the posts as a non registered user... it shows nothing.

Problem: I'm trying to display posts using wp_query and meta_query related between with AND operator and values added dynamic.

Question Why i can show the posts using the same syntax ONLY when i'm logged in but not when i'm logged out.

Additional infos I'm using wp_ajax, ACF plugin.

Code:

function filtering_program(){
  $luna = $_POST['data'][0];
  $ziua = $_POST['data'][1];

  $args = array(
    'post_type'      => 'program',
    'orderby'        => 'date',
    'order'          => 'DESC',
    'posts_per_page' => -1,
    'meta_query'     => array(
        'relation'     => 'AND',
        array(
          'key'        => 'ziua',
          'value'      => $ziua,
          'compare'    => 'LIKE'
        ),
        array(
          'key'        => 'luna_anului',
          'value'      => $luna_number,
          'compare'    => 'LIKE'
        )
    )
  );

  $posts = new WP_Query( $args );

  if ( $posts -> have_posts() ) {

  }

  wp_die();
}
add_action('wp_ajax_program_filter', 'filtering_program');
add_action('wp_ajax_nopriv_program_filter', 'filtering_program');

FUNCTIONS PHP ends here

From now on its the js handle and ajax request

$('.dd-program').click(function(){
        $this = $(this);

        if($(this).hasClass('options-month')){
            $datas[0] = $(this).parent().find('.selected-program-filter').html();
        }else{
            $datas[1] = $(this).parent().find('.selected-program-filter').html();
        }

        var payload = {
            'action': 'program_filter',
            'data': $datas
        };

        $.ajax({
            url: loadmore_params.ajaxurl,
            data: payload,
            type: 'POST',
            beforeSend : function ( xhr ) {
                $('.posts-data .container .flex-grid').addClass('isLoading');
                $('.posts-data .container .flex-grid').html('<div class="col"></div><div class="col"></div><div class="col"></div><div class="col"></div><div id="loading"></div>');
                $('.posts-load-more').css('display', 'none');
            },
            success : function( data ){
                console.log(data);

                if( data ) {
                    if($this.data("lang") == "RO"){
                        $('.posts-data .container .flex-grid').html(data.replaceArray([">Locatie<", "No posts!"], [">Locație<", "<h3>Nu exista evenimente!</h3>"]));
                    }else{
                        $('.posts-data .container .flex-grid').html(data.replaceArray([">Locatie<", "No posts!"], [">Location<", "<h3>No events!</h3>"]));
                    }
                }
            }
        });
    });
1

1 Answers

0
votes

In you js code try to replace all $ with jQuery.

For example:

$('.dd-program').click(function(){ 

replace with

jQuery('.dd-program').click(function(){ 

And the same for the rest of the code.