Post field search

Support General Post field search

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #46855
    Jayron CastroJayron Castro
    Participant

    I 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/gZ72mPp

    #46861
    PeterPeter
    Moderator

    Hello Jayron,

    You can filter posts by a field value by using the arguments meta_key and meta_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-parameters

    Let me know how it goes.

    #46947
    Jayron CastroJayron Castro
    Participant

    I 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/3Fn4Bvc

    #46951
    YasmineYasmine
    Participant

    Hi - 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,
                    ],
                ],
            ],
    
    #46952
    YasmineYasmine
    Participant

    I 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!

    #46955
    Jayron CastroJayron Castro
    Participant

    Thank you for your help, but the research has already worked.

    #46970
    PeterPeter
    Moderator

    Hello 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 the post field like that. Please follow the documentation
    https://developer.wordpress.org/reference/classes/wp_query/

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.