we have created a numeric field and added it to our CPT . In the WordPress Archive, we want to order the CPT with this new field. Unfortunately, nothing appeared to list from the existing CPT but if we create a new it appeared correctly.
Let me give you an example. I have 10 CPTs on a list without any order. I create a new checkbox and I added to the sort by option in the WordPress Archive. Then all CPT disappeared. I assume the value is null from them and this is the reason. If I create a new CPT with value in this new field its appeared correctly
We want to have a checkbox in the CPTs and when this checkbox is selected then appears at the top of the WordPress Archive list.
I understand what you mean now, in this case you will need to select another option for the checkbox for the posts that you don't want to appear on top.
This is because you can't sort posts by a null value, so all the other posts that don't have this checkbox checked won't appear.
I hope I was able to clarify this for you. So you can have 2 options Featured that stores a value of 1 and not featured that stores a value of 2.
Unless the post itself has been saved with that field a database entry is not made for that post with that custom field. Its not that null isn't sortable its that the database entry doesn't exist unless the post has been saved at least once with that field.
What you can do as a workaround is create a second view that will only display those featured items and add it to the archive itself.
This way you can still have the featured items as well as the non-featured ones.
Ok, we have created the new view with only the needed values, but how we will exclude these from the other view? Because now are displayed twice? If we add the new field as a filter to our main View, again nothing appears.
What you need to do is to replace "wpcf-customfieldslug" with the slug of the custom field keeping the wpcf- prefix and 'my_custom_post_type' with the slug of your custom post type.
Please let me know if this custom hook helps.
Thanks,
Shane