Hi,
Add this function into the functions.php file, like this: http://screencast.com/t/42g35dlHA
This will allow you to modify the sort order of post on category page:
function foo_modify_query_order( $query ) {
if ( $query->is_category() && $query->is_main_query() ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'DESC' );
}
}
add_action( 'pre_get_posts', 'foo_modify_query_order' );
Change the order as you like.
For the Mega menu you have to add this line of code $atts['sort'] = 'alphabetical_order';, like this:
http://screencast.com/t/0OmLDPNkD9U
Change the sort order as you like, using the values set for sort here: http://screencast.com/t/Gv2I6uUs
Thanks
Hi,
Please try to add also this to the above code – http://screencast.com/t/caXaQ9E7Xgcu
function foo_modify_query_order( $query ) {
if ( $query->is_category() || $query->is_tag() && $query->is_main_query() ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'DESC' );
}
}
add_action( 'pre_get_posts', 'foo_modify_query_order' );
Thanks!
-
This reply was modified 11 years by
Alin [tagDiv].
Hi Lucian,
That is exactly what I need – Unfortunately both screencast links (added in blockquote) are not able to be displayed anymore. Is it possible for you to update them?! That would be a great help. Thanks in advance!
Hi,
Add this function into the
functions.php
file, like this: http://screencast.com/t/42g35dlHA
This will allow you to modify the sort order of post on category page:function foo_modify_query_order( $query ) { if ( $query->is_category() && $query->is_main_query() ) { $query->set( ‘orderby’, ‘title’ ); $query->set( ‘order’, ‘DESC’ ); } } add_action( ‘pre_get_posts’, ‘foo_modify_query_order’ );
Change the order as you like.
For the Mega menu you have to add this line of code
$atts[‘sort’] = ‘alphabetical_order’;
, like this:
http://screencast.com/t/0OmLDPNkD9U
Change the sort order as you like, using the values set for sort here: http://screencast.com/t/Gv2I6uUsThanks
Hi Lucian.
I am trying to sort posts in category “camera-eye” (nr. 306) in the mega menu according to a custom field called “concertdatum”. However I keep failing miserably.
For this to work I have added the sorting option concertdatum like so:
/includes/wp_booster/td_data_source.php
case 'concertdatum':
$wp_query_args['meta_key'] = 'datum';
$wp_query_args['meta_type'] = 'DATETIME';
$wp_query_args['orderby'] = 'meta_value';
$wp_query_args['order'] = 'DESC';
break;
Then I have changed the following to the mega menu file:
/includes/shortcodes/td_block_mega_menu.php
class td_block_mega_menu extends td_block {
function render($atts, $content = null){
if (is_category( '306' )){
$atts['sort'] = 'concertdatum';
parent::render($atts);}
$buffy_categories = '';
extract(shortcode_atts(
array(
'limit' => 5,
'sort' => '',
'category_id' => '',
'category_ids' => '',
'custom_title' => '',
'custom_url' => '',
'show_child_cat' => '', //the child category number
'sub_cat_ajax' => '' //empty we use ajax
), $atts));
if (!empty($show_child_cat) and
!empty($category_id)) {
// check for subcats existence
$td_subcats = get_categories(array(
'child_of' => $category_id,
'number' => 1
));
if (!empty($td_subcats)) {
$atts['limit'] = 4; //alter the loop because we don't have space now with the categories
}
}
parent::render($atts); // sets the live atts, $this->atts, $this->block_uid, $this->td_query (it runs the query)
//get subcategories, it returns false if there are no categories
$get_block_sub_cats = $this->get_mega_menu_subcategories($atts);
$additional_classes = array();
But sadly nothing happens, can you help me out what I’m doing wrong please ?
-
This reply was modified 7 years by
NickDeBaerdemaeker.
-
This reply was modified 7 years by
NickDeBaerdemaeker.
Hi NickDeBaerdemaeker,
Unfortunately, this is not a simple task and if you are not aware of the steps which are needed to take in this case, please consider hiring a freelancer/developer to help you because we cannot provide custom work at the moment, sorry! We cannot provide additional customization at the moment, sorry! You can try using such a plugin with this functionality from here -> https://wordpress.org/plugins/custom-taxonomy-order-ne/
The plugin Category Order and Taxonomy Terms Order might be useful to you because I saw that many users use it to change the categories order.
Hope this helps!
Thanks.