Ask your WordPress questions! Pay money and get answers fast! (more info)

Quote for Event List with ACF plugin and Callback Ajax on News WordPress

Scenario:
here is my temporary website http://www.kickproduction.it/dna/

1 - CALENDARIO
I have to many artist, and someone has on tour, for every band (post) I create a repeater custom filed for their gigs(concerts).

The repeater fields are: date, venue, location and more

IN my Event List (CALENDARIO), i would to see only the band with upcoming date concert, and if one band has for example 1 past concert and 1 upcoming concert, I would to see only the Upcoming concert.

Also, the event list (CALENDARIO) has to be order by Concert, and then by Title (this is working now, but I need to hide the past concert, and reorder only by upcoming concerts.)

this is actual code:


<?php

// custom filter to replace '=' with 'LIKE'
function my_posts_where( $where )
{
$where = str_replace("meta_key = 'gigs_%_data'", "meta_key LIKE 'gigs_%_data'", $where);

return $where;
}

add_filter('posts_where', 'my_posts_where');
$today = date('yymmdd');
// args
$args = array(
'numberposts' => -1,
'post_type' => 'post',
'meta_key' => 'gigs_%_data',
'orderby' => 'meta_value_num title',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'gigs_%_data',
'value' => $today,
'compare' => '>=',
)
)
);

// get results
$the_query = new WP_Query( $args );

// The Loop
?>
<?php if( $the_query->have_posts() ): ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="starmite-row clearfix">
<div class="starmite-fourthy item toura">
<article <?php post_class('clearfix'); ?>>
<a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail('thumbnail'); ?>
<p><?php the_title(); ?></p>
</a>
</article>
</div>

<div class="date">

<?php if( have_rows('gigs') ): ?>

<?php while( have_rows('gigs') ): the_row(); ?>

<div>
<?php
setlocale(LC_TIME, 'it_IT');
echo strftime("%d %B %Y", strtotime(get_sub_field('data', get_the_ID() )));
?>


| <?php the_sub_field('città'); ?> | <?php the_sub_field('venue'); ?> | <?php the_sub_field('info'); ?>

<?php if( get_sub_field( "acquista" ) ): ?>
| <a href="<?php the_sub_field( "acquista" ); ?>" target="_blank">ACQUISTA</a>
<?php endif; ?>

</div>

<?php endwhile; ?>
<?php endif; ?>

</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>



2 - AJAX LOAD MORE with CALLBACK

ever on http://www.kickproduction.it/dna/
you can see the NEWS section, this loop load 25 posts, and when you click on one news (for example: "Wampire: tre date a Novembre!" ), you can see the post loaded on center DIV via AJAX.

Now, if you go down on the same section, and click load more button, you have other 25 posts, but if you click on the new one (for example: "Kodaline in Italia a Dicembre!"), you haven't the same behavior.

So, the first 25 post load the code ( Ajax Load Single Post in center DIV ), the second page (post from 26 to 50 ) doesn't load the ( Ajax Load Single Post in center DIV ).

this is my code:



jQuery.noConflict();
jQuery(document).ready(function($){
// Ajax Load Single Post in center DIV
$.ajaxSetup({cache:false});
$("a.ajarts").click(function(){
var post_url = $(this).attr("href");
var post_id = $(this).attr("rel");
$("#loadin").html('<div class="loading"><img src="http://www.kickproduction.it/dna/img/loading.gif" height="400" /></div>');
$("#loadin").load(post_url);

return false;
});
});

jQuery.noConflict();
(function($) {
// Ajax-fetching "Load more posts"
$('.fetch a').live('click', function(e) {
e.preventDefault();
$(this).addClass('load-ing').text('loading...');
$.ajax({
type: "GET",
url: $(this).attr('href') + '#news ul.news',
dataType: "html",
success: function(out) {
result = $(out).find('#news ul.news li');
nextlink = $(out).find('.fetch a').attr('href');
$('#news ul.news').append(result);
$('.fetch a').removeClass('load-ing').text('V');
if (nextlink != undefined) {
$('.fetch a').attr('href', nextlink);
} else {
$('.fetch').remove();
}
}
});
});
})(jQuery);

Answers (1)

2013-12-11

Arnav Joy answers:

to disable past date use this query posts , you have to pass type="numeric" in meta_query

<?php

$args = array(

'numberposts' => -1,

'post_type' => 'post',

'meta_key' => 'gigs_%_data',

'orderby' => 'meta_value_num title',

'order' => 'ASC',

'meta_query' => array(

array(

'key' => 'gigs_%_data',

'value' => $today,

'compare' => '>=',

'type' => 'numeric'
)

)

);



// get results

$the_query = new WP_Query( $args );
?>


Manlio Ma comments:

whit this line crash all loop. but i don't need to hide entire post, but only custom field that is lower than today date.
something like ...

if sub_field ( data ) is >= today
echo sub_field ( data )
else
do nothing
endif