Home › Forums › General Issues › Category Query
I am using Genesis Magazine Pro. I have a custom category template that replaces the genesis_do_loop with a custom loop.
I have ordered the query by DESC order (the default) with the default orderby (date) and it works fine, with all content displaying properly and in order. But when I switch it to ASC order it fails and no output is generated at all. The page title, sidebar, header, footer all display but not the page content.
The content is all via ACF fields within regular posts (NOT a custom post type).
These are the parameters:
$args = array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => '20', 'orderby' => 'date', 'order' => 'DESC' );
Thanks for reaaching out to us.
Something is not clear, is date an ACF field? Doing a var_dump of the get_post, are the posts being returned as expected with the orderby status set?
Kindly share more information on your setup so that I may be able to advise further.
Hope to hear from you soon.
“Date” is the WP default post_date not an ACF field. I know it doesn’t need to be there since it’s a default, I just added it as part of my debugging as I was trying out other values.
My site is currently local and I am not at the office right now so I will try the var_dump later and see what comes up.
Thanks for the follow up.
Do test it out and let me know how it goes.
To be honest I really have never done a var_dump before. I’ve looked into it and tried a few things but can’t seem to get it to work the way it needs to. It just dumps out a bunch of data I can read but not make much sense of. Then below it spits out the content in DESC order.
This is my var_dump. I know it’s not right but I don’t know how to get it to where I need it and I’m not even sure it’s placed properly in the template. I’ve placed it just inside the custom loop function and before the query args:
$myVar = get_posts(); var_dump ($myVar);
If it helps, some background…. I have a page called “Executive” and a custom category template to display it. The template displays content from a regular post category called “Executive”. The posts’ content is created using 3 ACF fields. All of the content displays fine when the default DESC order is used but when I switch it to ASC order, it fails and no post content is displayed (global header, footer etc display fine). The reason I need ASC order is because the content doesn’t follow any alphabetical or other priority order, just the date each post was input. Yes, I could re-enter all the posts in backwards sequence and use DESC order but what’s the fun in that? 🙂
Thanks for your help James! I worked out a solution using pre_get_posts to get the order working properly.
Glad to have been able to help.
Feel free to let me know in case something else comes up 🙂
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.