• Resolved maddoctor

    (@maddoctor)


    I added the same tag names on my posts and my custom post type, when I click on the tag on any page, it redirects as if I clicked on the tag on a post, not my custom post type. It works fine from within the admin, but not on the frontend. Any ideas?

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    It sounds like you’re arriving at the archives for the tags, but the post type posts you set up aren’t shown in that archive.

    I’d give this documentation page a readover and try out the code there.

    https://docs.pluginize.com/article/17-post-types-in-category-tag-archives

    If you need any help with that code, let me know.

    Thread Starter maddoctor

    (@maddoctor)

    Thank you for the answer! It works as expected. I have one question though, I have a custom field (using Advanced Custom Fields) in my custom post type called “Available”, how can I make only posts that have Available:yes appear on the archive? Because with that code all custom posts appear.

    I figure I need to use something like this:
    $query->query_vars[“meta_key”] = ‘available’;
    $query->query_vars[“meta_value”] = ‘yes’;

    And modify this part of the code:
    $query->set(
    ‘post_type’,
    array_merge(
    array( ‘post’ ),
    $cptui_post_types
    )
    );

    but where exactly?

    • This reply was modified 6 years, 4 months ago by maddoctor.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    If my previous experience tells me anything, I think you’d use the $query->set() method to set a meta_query parameter.

    Similar to this from the WP_Query codex page:

    $args = array(
    	'post_type'  => 'product',
    	'meta_query' => array(
    		array(
    			'key'     => 'color',
    			'value'   => 'blue',
    			'compare' => 'NOT LIKE',
    		),
    	),
    );
    $query = new WP_Query( $args );
    

    You would do something like:

    $query->set(
        'meta_query',
        array( array( 'key' => 'available', 'value' => 'yes' ) )
    );
    

    Worth a try at least ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Post and Custom Post categories’ is closed to new replies.