Skip Navigation

[Closed] Sort view by page order

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Tagged: 

This topic contains 7 replies, has 2 voices.

Last updated by Minesh 5 years, 1 month ago.

Assigned support staff: Minesh.

Author
Posts
#319991

Hi,

I want to sort a view by the wordpress page order, I'm using this plugin https://wordpress.org/plugins/intuitive-custom-post-order/ to set the post order easily in wp admin - but how do I get views to reflect it?

Thanks

#320084

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello and thank you for contacting Toolset support.

With views, you can order your posts with custom fields, you can check if the custom field that maintain the order using your plugin, is that custom field is available when you edit your views under "Ordering" section drop-down.

if it’s not available there, perhaps it’s a custom field, you can bring custom field under Types control from:
=> Types => Custom field control

Once your custom field is successfully imported to Types, you can check the "Ordering" drop-down for same field and set "order by", your custom field.

Or

You may use "wpv_filter_query" hook.
=> https://toolset.com/documentation/user-guides/views-filters/wpv_filter_query/

This are the ways you may able to set your post order. Otherwise you may contact your plugin author to help on this.

#320319

Hi,

It has sort by menu order which I would have thought would work - but it just ignores it. That plugin just uses the default wordpress 'order' attribute.

Thanks

#320377

We had a filter overriding it, working nicely now but - i need a better way of determining which view is being used, on some pages we have nested views, which may be ordered differently.

How do I detect the view ID being used?

// USER SORTING QUERY
add_filter('posts_orderby', 'my_client_order', 98, 2);

function my_client_order($order, $q) {
if (!empty($_GET["wpv-sort"])) {
$sort = $_GET["wpv-sort"];

if ($sort == 'alpha-asc') {
return 'post_title ASC';
}

if ($sort == 'alpha-desc') {
return 'post_title DESC';
}
//---
//Support from wp-types:
if ($sort == 'date-asc') {
return 'post_date ASC';
}

if ($sort == 'date-desc') {
return 'post_date DESC';
}
//---
} else {

//return 'post_date DESC';
return 'menu_order DESC';
}
}

#320395

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please try to use global variable $WP_Views.

For example:

global $WP_Views;
 if($WP_Views->current_view == 1234){
//do something you want
}
#320722

Will try that, how does that work with nested views or multiple views on a page?

#320724

Ok that's working nicely, now I just need to add in the option to turn this on and off - what's the best way?

- Add a new checkbox to the page where the view is inserted, check if this is checked
- Use a shortcode attribute on the view

How can I check a types field value on the page where the view is insert from within the above code?

Thanks

#320731

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Glad to hear that your original issue is fixed.

As the original issue is resolved may I kindly ask you please to open a new ticket for your new question and mark this thread as resolved. This will also help other users with similar problems find solutions when searching the forum.

Thank you for understanding.

The topic ‘[Closed] Sort view by page order’ is closed to new replies.