Post field search
- This topic has 6 replies, 3 voices, and was last updated 5 months, 2 weeks ago by
Peter.
-
AuthorPosts
-
November 6, 2024 at 6:35 AM #46855
Jayron Castro
ParticipantI created a Post Type called Courses, then I created a custom field of type switch and attached it to the course post, my goal is to be able to enable or disable a course, until now it is working normally.
Then I created a second post type called Classes, created a custom field of post type and advanced selection subtype, attached it to the classes post and all the courses are showing.
My question is how do I display only courses that have the switch field enabled, that is, I don't want disabled courses to appear.
How do I do this configuration?
- https://ibb.co/42FWh12
- https://ibb.co/26VhBrV
- https://ibb.co/3d0dJmQ
- https://ibb.co/0DLjy2Q
- https://ibb.co/gZ72mPpNovember 6, 2024 at 9:12 PM #46861Peter
ModeratorHello Jayron,
You can filter posts by a field value by using the arguments
meta_key
andmeta_value
in the query args option. Please check this screenshot https://imgur.com/yFXnr4K
and follow the WordPress documentation https://developer.wordpress.org/reference/classes/wp_query/#custom-field-post-meta-parametersLet me know how it goes.
November 17, 2024 at 8:39 AM #46947Jayron Castro
ParticipantI need to return only users registered with the 'teacher' profile, I used the query args field but did not get the expected return, because like the attached image, the value is serialized in the database.
How can I solve it?
https://ibb.co/qRyjJxP
https://ibb.co/TtCxxwJ
https://ibb.co/3Fn4BvcNovember 18, 2024 at 5:53 PM #46951Yasmine
ParticipantHi - I came on here to see if you had issues with select_advanced search on a post field.
I filter by taxonomy on mine (so need to change to meta_key / meta_value), but incase it is helpful for structure, I use this:
'query_args' => [ 'post_status' => 'publish', 'tax_query' => [ [ 'taxonomy' => 'institution-category', 'field' => 'term_id', 'terms' => $filterterms, ], ], ],
November 18, 2024 at 5:57 PM #46952Yasmine
ParticipantI also didn't read what you needed properly and thought you wanted to see how to structure / dynamically get filter by post_author. Ignore me!
November 18, 2024 at 10:00 PM #46955Jayron Castro
ParticipantThank you for your help, but the research has already worked.
November 19, 2024 at 11:11 PM #46970Peter
ModeratorHello Jayron,
wp_capabilities
is a user meta, not a post meta, that you can add to the WP Query to query posts. WordPress doesn't support query posts by user capability so it isn't possible to add capability to thepost
field like that. Please follow the documentation
https://developer.wordpress.org/reference/classes/wp_query/ -
AuthorPosts
- You must be logged in to reply to this topic.