ACF filter

This topic contains 6 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 2 years, 9 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #33805
    Emanuele09
    Emanuele09
    Participant

    Hi i have problem with ACF filter,
    in function.php file i put this function:
    if( isset( $_POST[‘Cancellazione’] ) && ($_POST[‘Cancellazione’] == ‘on’ ))
    $args[‘meta_query’]= array(
    array(
    ‘meta_key’ => ‘cancgratis’,
    ‘meta_value’ => ‘1’,
    ‘meta_compare’ => ‘=’,
    ));
    “Cancellazione” is a checkbox, all other function who filter on type works fine, but meta_query with acf dont’s work.

    #33810
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    The key for the meta query is different, it is post_meta_filter.

    $args['post_meta_filter']= array(array(
    	'key' => 'cancgratis',
    	'value' => '1',
    	'operator => '=',
    ));

    You can check that whole documentation on how to change the plugin query arguments.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #33811
    Emanuele09
    Emanuele09
    Participant

    Hi Ernest,
    thank you for your suggestion, only I tried but it doesn’t work, can I provide you with screens or logs that can help you understand why?

    #33812
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Well, but I need to understand exactly what do you want to achieve with this?

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #33813
    Emanuele09
    Emanuele09
    Participant

    It’s simple:
    see “file1″,
    i want filter post on the right on check on the left. The top 5 options filter posts by taxonomies and works fine with this code:
    add_action(‘wp_ajax_myfilter’, ‘misha_filter_function’); // wp_ajax_{ACTION HERE}
    add_action(‘wp_ajax_nopriv_myfilter’, ‘misha_filter_function’);

    function misha_filter_function(){
    $page = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
    $args = array(
    ‘posts_per_page’=>6,
    ‘post_type’ => ‘tour’,
    ‘orderby’ => ‘data’, // we will sort posts by date
    ‘order’ => ‘DESC’, // ASC or DESC
    ‘paged’=> $page,

    );

    // for taxonomies / categories
    if( isset( $_POST[‘Avventura’] ) && $_POST[‘Avventura’] == ‘on’ )
    $args[‘tax_query’] = array(
    array(
    ‘taxonomy’ => ‘tipologia’,
    ‘field’ => ‘slug’,
    ‘terms’ => ‘avventura’,
    )
    );
    if( isset( $_POST[‘Relax’] ) && $_POST[‘Relax’] == ‘on’ )
    $args[‘tax_query’] = array(
    array(
    ‘taxonomy’ => ‘tipologia’,
    ‘field’ => ‘slug’,
    ‘terms’ => ‘relax’,
    )
    );
    if( isset( $_POST[‘Food’] ) && $_POST[‘Food’] == ‘on’ )
    $args[‘tax_query’] = array(
    array(
    ‘taxonomy’ => ‘tipologia’,
    ‘field’ => ‘slug’,
    ‘terms’ => ‘food’,
    )
    );
    if( isset( $_POST[‘Cultura’] ) && $_POST[‘Cultura’] == ‘on’ )
    $args[‘tax_query’] = array(
    array(
    ‘taxonomy’ => ‘tipologia’,
    ‘field’ => ‘slug’,
    ‘terms’ => ‘cultura’,
    )
    );
    if( isset( $_POST[‘Green’] ) && $_POST[‘Green’] == ‘on’ )
    $args[‘tax_query’] = array(
    array(
    ‘taxonomy’ => ‘tipologia’,
    ‘field’ => ‘slug’,
    ‘terms’ => ‘green’,
    )
    );

    while the code to be able to filter through custom field is this:

    if( isset( $_POST[‘Cancellazione’] ) && ($_POST[‘Cancellazione’] == ‘on’ ))
    $args[‘meta_query’]= array(
    array(
    ‘meta_key’ => ‘cancgratis’,
    ‘meta_value’ => ‘1’,
    ‘meta_compare’ => ‘=’,
    ));

    the code ends as follows:

    $tour = new WP_Query( $args );

    echo ‘<div class=”row”>’;
    $i=0;

    if( $tour->have_posts() ) :
    while( $tour->have_posts() ){
    $tour->the_post();
    $tipologia=get_the_terms(get_the_ID(),’tipologia’);
    $tipologia_nome=$tipologia[0]->name;
    $tipologia_slug=$tipologia[0]->slug;
    $tipologia_link=get_term_link($tipologia[0]->term_id,’tipologia’);
    $imgrap_tour= get_field(‘immagine_rappresentativa’);
    $titolo_tour= get_field(‘titolo’);
    $prezzo_tour= get_field(‘prezzo’);
    $cancgratis= get_field(‘cancellazione_gratuita’);

    echo ‘<div class=”col-4 pa-15″>’;
    echo ‘<div class=”tour-page-1″ style=”background-image:’.’url(‘.$imgrap_tour.’)’.’;background-position: center; background-repeat: no-repeat;background-size: cover;”><div class=”overlay”><h3 class=”cat-tour”>’.$tipologia_nome.'</h3>’;
    echo ‘<div class=”row row-titolo-tour-page”><h2 class=”margin-x-auto titolo-tour-page-1″>’.$titolo_tour.'</h2></div>’;
    echo ‘<div class=”row”><h1 class=”margin-x-auto prezzo-tour-page”>da € ‘.$prezzo_tour.'</h2></div>’;
    if($cancgratis){
    echo ‘<div class=”row”><h2 class=”margin-x-auto canc-gratis-tour-page”>CANCELLAZIONE GRATUITA*</h2></div>’;
    }
    echo ‘<div class=”row center”>ACQUISTA</div>’;
    echo ‘</div></div></div>’;

    }

    wp_reset_postdata();
    echo ‘<div class=”row padding-navigator”>
    <div class=”bordi-navigator”>’;
    echo easy_wp_pagenavigation( $tour );
    echo ‘</div></div>’;
    else :
    echo ‘No posts found’;
    endif;

    die();
    }

    as you can see from file 2 the desired result is to filter the posts and not reload the page.

    if it can help I sent you the tour file.php which contains the layout of the page, and functions.php which contains the functions I’m talking about

    thank you for your help.

    Emanuele

    Attachments:
    You must be logged in to view attached files.
    #33816
    Emanuele09
    Emanuele09
    Participant

    excuse me i can’t send php files even adding them to an archive

    • This reply was modified 2 years, 9 months ago by Emanuele09 Emanuele09.
    #33827
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Thank you!

    The checkgoxes on the page, and the filter section are not coming from this plugin. You seem to have a custom query feature, which you want to modify via the filter checkboxes. I understand that, but this is completely unrelated to this plugin. The checkboxes seem to be printed by the theme your are using, at least the styling refers to the theme files.
    You may have to ask the theme support about these features.

    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.