Custom Fields
Re-Envisioned
Support MB Custom Post Type Tag Query - pre_get_post - CPT

  • Creator
    Topic
  • #28820
    Resolved Prabakaran Shankar
    Participant

    Post Tag and category were registered for the CPTS. however, the tag and category query has not been working.
    Hence, I have added the below snippet to execute the function.
    'function job_cpt_tags( $query ) {
    if ( $query->is_tag() && $query->is_main_query() ) {
    if ( $query->is_search ) {
    $query->set( 'post_type', array( 'post', 'job' ) );
    }
    }
    }
    add_action( 'pre_get_posts', 'job_cpt_tags' );
    function job_cpt_category( $query ) {
    if ( $query->is_category() && $query->is_main_query() ) {
    if ( $query->is_search ) {
    $query->set( 'post_type', array( 'post', 'job' ) );
    }}
    }
    add_action( 'pre_get_posts', 'job_cpt_category' );'

    For 1 CPT this is fine. But, if there are many CPTS, better to be included in the module.

    Please include this function in the MB CPT module and consider this as a feature request.

  • You must be logged in to reply to this topic.