Hi Rob,
Not sure if the code in the example is deprecated or not, but here is the code I use on the archives on ALM website.
$cat = get_query_var('cat');
$category = get_category ($cat);
echo do_shortcode('[ajax_load_more seo="true" preloaded="true" preloaded_amount="4" posts_per_page="4" category="'.$category->slug.'" images_loaded="true" repeater="template_19" pause="true" pause_override="true"]');
Cheers,
Thanks, that’s fixed the error problem perfectly. Now I need to try and set up this rather complicated query – basically the items I’m loading have a custom field (a date), and I want to only show items for which the date is equal to today or in the future.
The original query for the loop looks like this:
<?php
// args
$today = date("Ymd");
$args = array (
'post_type' => 'book',
'cat' => $cat,
'showposts' => '8',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'hbk_publication_date',
'compare' => '>=',
'value' => $today,
),
array(
'key' => 'pbk_publication_date',
'compare' => '>=',
'value' => $today,
),
),
);
// get results
$the_query = new WP_Query( $args );
// The Loop
?>
I then want ALM to show further posts based on that query. Is that doable?
Thanks for your help.
Yea.
In your template, something like the following:
$today = date("Ymd");
echo do_shortcode('[ajax_load_more post_type="book" category="'.$category->slug.' meta_key="hbk_publication_date:pbk_publication_date" meta_value="'.$today.':'.$today.'" meta_compare=">=:>=" meta_type="CHAR:CHAR" meta_relation="OR" orderby="meta_value_num" order="DESC"]');
The meta_type should maybe be DATETIME or DATE… You might need to play around with that.
Thanks, that’s very nearly perfect. The only problem I’m having is that it isn’ replicating the same order as the query I pasted above – that loop shows 8 items, so I’m using an offset value of 8 in order to follow on from there. The issue is that it’s not offsetting the same 8 items. I’ve tried changing the meta_type value and also playing with the order, but with no luck.
The query you posted is not ordering on a meta_key, which is required if you set orderby -> meta_value_num.
By default Ajax Load More will order by the first meta_key listed, so i your case it is ordering by hbk_publication_date
If you don’t want to order by this meta_key then remove the orderby parameter in your shortcode.
Basically, what i’m saying is your query is likely not ordering by meta_value_num.
Confused yet? 🙂
Yes, very confused!
Basically what I want to do is this: order by hbk_publication_date, or if it isn’t present, by hbk_publication_date and to show the ones closest to today first. They will all be in the future.
Sorry, I missed your response here.
Yea, what im saying is your original query:
<?php
// args
$today = date("Ymd");
$args = array (
'post_type' => 'book',
'cat' => $cat,
'showposts' => '8',
'orderby' => 'meta_value_num',
'order' => 'DESC',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'hbk_publication_date',
'compare' => '>=',
'value' => $today,
),
array(
'key' => 'pbk_publication_date',
'compare' => '>=',
'value' => $today,
),
),
);
?>
is not ordering by meta_key. I believe that even though you have a meta_query, you still need to specify the key.
See this example.
http://wordpress.stackexchange.com/a/15499/12868
I see. My understanding was that the ‘key’ listed in the array further down in the query replaced that – there are two possible values, hbk_publication_date and pbk_publication_date, so it had to be set this way.
Is it not possible to use this same query model with ALM? I’m not sure how else I can build two meta_key queries into the original query.
Thanks
From the codex:
‘meta_value_num’ – Order by numeric meta value (available since Version 2.8). Also note that a ‘meta_key=keyname’ must also be present in the query. This value allows for numerical sorting as noted above in ‘meta_value’.
ALM automatically sets meta_key for you if you set ‘orderby=”meta_value_num”‘ so you would need to use the alm_modify_query_arg filter to set $args['meta_key'] = ""
Again, the issue is actually in your original query. It’s not actually ordering by the meta_value_num.