This support ticket is created Il y a 3 années et 2 mois. 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.
Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.
I am trying to create a view that displays and searches content from three different post types: posts, courses, and lessons. Posts may contain a custom field called "superseded" that has a 1 if checked and 0 if unchecked (although I've found it doesn't always record a zero if unchecked). Courses and lessons do NOT have the custom field "superseded".
I would like the view to only display content that does NOT have a superseded=1 value. It SHOULD display the content if the superseded value is either zero or non-existent. However, any filter whatsoever I try to put on eliminates all records from the output. Any help would be appreciated. Thanks.
Les langues: Anglais (English )Espagnol (Español )
Fuseau horaire: Europe/London (GMT+00:00)
>It SHOULD display the content if the superseded value is either zero or non-existent.
The problem here is with "non-existant".
Under the hood Views queries the database via the core WP_Query class, and when you add a custom field filter the results that will be returned must have a value for the custom field (which then matches the specified condition, in this case not equal 1).
(More accurately, the custom field must have an entry in wp_postmeta for the post, even if the value is empty.)
So, for your posts to be shown you should make the custom field available to each of the post types, make sure that it is set to save 0 to the database if unchecked, and edit and save the posts so that they update wp_postmeta to include an entry for the custom field.
Check the documentation for WP_Query about how to use the meta_query parameter where you could check for whether the key NOT EXISTS or was not equal to 1.
It seems the easiest solution is to make the superseded field available to the other post types. However, there is one wrinkle in the plan. It is currently part of a field group and I don't want to make all the other fields also available to the other post types. Is there a way to migrate the custom field from one field group to another without fouling up the data in the posts? Thanks.
There is actually the option to re-use previously created custom fields.
What you can do is to go to the field group that is assigned to another post type then add a new field. From there you should see the button "Choose from previously created fields."
Once you click the button it should bring up all your existing custom fields for you to add it to the field group.