admin管理员组文章数量:1415100
I am trying to create a custom way to order my new custom post type.
Here is what I am envisioning:
- There would be a custom way to order posts in an entirely unique order for display (Number, automatic value, etc.) This would be so I could avoid needing to manually change a ton of publication dates on posts to get the right order.
- If there was no number/automatic value/etc. entered then it would display based on when it was published at the end of the list.
I am using CMB2 for the meta-data fields on my custom post type.
Does anyone have any suggestions or ideas? I realize that this is a complicated problem, but I want to be able to order posts in a custom order that is not by author, date published, or title.
I am trying to create a custom way to order my new custom post type.
Here is what I am envisioning:
- There would be a custom way to order posts in an entirely unique order for display (Number, automatic value, etc.) This would be so I could avoid needing to manually change a ton of publication dates on posts to get the right order.
- If there was no number/automatic value/etc. entered then it would display based on when it was published at the end of the list.
I am using CMB2 for the meta-data fields on my custom post type.
Does anyone have any suggestions or ideas? I realize that this is a complicated problem, but I want to be able to order posts in a custom order that is not by author, date published, or title.
Share Improve this question asked Aug 25, 2019 at 16:28 MichaelMichael 881 silver badge7 bronze badges2 Answers
Reset to default 1With register_post_type()
, you can specify the 'page-attributes' => true
property, and you'll get the "menu order" metabox which you see on pages. With this you can custom order your items, where the default is always 0, which means they will always show, even if you don't set a value.
You don't actually have to set the page-attributes
attribute to use the the menu_order
post property/column. You can set that value programmatically. To query with the custom ordering in place, you can use the menu_order
property in your WP_Query
args: https://developer.wordpress/reference/classes/wp_query/#order-orderby-parameters
You could just add a 'priority' or 'order' custom field (number) to your post type and order based on that.
See Custom query with orderby meta_value of custom field, wp_query / #order-orderby-parameters
本文标签: Order Posts in Custom Order
版权声明:本文标题:Order Posts in Custom Order 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745154585a2645091.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论