Skip Navigation

[Resolved] Display Taxonomy Posts First

This support ticket is created 4 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 3 replies, has 2 voices.

Last updated by Armando 4 years, 11 months ago.

Assisted by: Beda.

Author
Posts
#1226576

Tell us what you are trying to do?
I have a CPT and a associated taxonomy. I would like to display all post types that have the taxonomy first and then the rest.

Lets say I have 20 posts. Only 3 are tagged "premium". I would like to show:

Premium Premium Premium Post Post Post Post Post Post ....

Is it possible to do this in one view? I would prefer to not break it up since then it will display int two different 'blocks'.

I also need this to be searchable, so the search results would be the same sort order. I can handle the search, I just need a bit of help with the above.

Thank you so much!!!

#1226600

EDIT: I can also use a custom field as a sorting method. I created a radio button group (yes and no, value 1,2). I tried to use the sort ordering in the view, I guess I don't understand how that works. Thanks!

#1226646

That should be possible by using 2 views, as one View will respond to the query (by taxonomy) and hence exclude all posts, not within that taxonomy.
The second View will then respond to the second query (all posts not in a certain taxonomy)

Hence, you can set up 2 Views.
The first has a query to return posts in a term XY, and complete the Loop.
Then the second View will have a Query that returns all posts NOT in the term XY, and also here complete the loop.
Then, either insert the second view just below the [wpv-layout-meta-html] in the first View's Output Editor, and that first View to a page, or both Views below each other in a page.

To solve the "2 different blocks" issue, you could check the box "Disable the wrapping DIV around the View" in each of the views, which will ensure no additional HTML is wrapped around your loops, hence, you'll not end up with too many Divs in a page.

About sorting, you would still have the issue that a View, just as the WordPress query, will always listen to what you set in it, so if you exclude posts that are not in a term, or include posts in a term, it will and can only listen to that.
So you will need to have either 2 Views or no query in the view.

You could for example order by terms. This means, create a Taxonomy View, order by Terms, and then list the posts in that view.
This would ensure that posts with term A come before Term B, but you still could not show posts without any term at all.
(since those would be excluded from the query by the ordering)

Related to search, you should be able to add search handles manually (means, you need to populate a custom link or select that once clicked, updates the URL with a URL parameter)
If then you set both views to listen to the same URL parameter, both will get updated on search.
But this cannot work with View's inbuilt search, as it adds Views-ID's so to make sure, only the view searched will be updated

#1228028

My issue is resolved now. Thank you!

I used the second method I mentioned above.

Steps:

1- Create a custom field with a numeric value to set as a flag. I called mine "Premium" with a default value of 2.

2- I created one View with the following:
Oder By: Premium (My custom field)
Secondary Order: Post Date

Any "Premium" posts I want at the top have a value of 1.

Done. Thanks!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.