Sort one category differently in mega menu

Posted in: Newspaper
Post count: 101

Hi,

the mega menu currently sorts all posts from any category according to date, most recently published first.

However we are at the moment working on adding a huge amount of posts from the past, which have a custom field “datum” set to the date of the event that it happened. So it can happen that an event from let’s say april 20th 2018, will have the correct date set in the “datum” field, but will be published by the date of today.

We would like to make this change for just one category, called camera_eye, where the posts should be published according to event date, not published date.

How would we achieve this ?
I already figured out where I could be doing this, given this post on your site earlier: http://www.screencast.com/t/jgjknQvhwDwh

We think this is one of the bits of code, but obviously we’d need to define asc or desc, and the custom field “datum”, we’re fairly sure that like this it won’t work.

$att['sort'] = 'datum'
parent::render($atts);
Post count: 35449

Hi,

Please read this documentations
-> https://codex.wordpress.org/Alphabetizing_Posts
-> https://codex.wordpress.org/Class_Reference/WP_Query
Hope this will help you to achieve what you want.

Thank you for your understanding.

  • This reply was modified 7 years by Calin.
Post count: 101

Im unsure what you mean by these links.
Do I have to create a category.php file, specific camera eye php file or simply use the code shown on these pages and insert that into the td black mega menu file from the theme ?

Post count: 35449

Hi,

I thick you need to add some conditions in mega menu file, if is that category then do the sort after event date, unfortunately I do not know hot to do this, sorry.

Thank you for your understanding.

Post count: 101

So far I got this, but yet again it’s still not behaving like it should.
Code is correct though, when I alter else { $wp_query_args['order'] = 'DESC'; to ascending it works, however the category if is not picked up…

case 'snort':
if (is_category( 'camera-eye' )) {
$wp_query_args['meta_query'] = array(
'datum_clause' => array('key' => 'datum','compare' => 'EXISTS')
);
$wp_query_args['orderby'] = array('datum_clause' => 'DESC', 'post_date' => 'DESC');
} else { $wp_query_args['order'] = 'DESC';
}
break;

Post count: 35449

Hi,

Unfortunately I do not know what is wrong in your code, or how to help you to achieve the right code for this, sorry.

Thank you for your understanding.

Viewing 6 posts - 1 through 6 (of 6 total)
The forum ‘Newspaper’ is closed to new topics and replies.