Forum Replies Created
-
AuthorPosts
-
Emanuele09
Participantexcuse me i can’t send php files even adding them to an archive
-
This reply was modified 4 years, 11 months ago by
Emanuele09.
Emanuele09
ParticipantIt’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
Emanuele09
ParticipantHi 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? -
This reply was modified 4 years, 11 months ago by
-
AuthorPosts