WordPress.org

Ready to get started?Download WordPress

Forums

  1. User45
    Member
    Posted 1 year ago #

    Hi,

    I have setup Custom Post Types and almost everything work fine, but there is one issue.

    Post is related to existing WP Category, when I click on the Category on the Post's page then 404 error showed up.

    Why this Custom Post is not in the Category Archive Page?

    Settings of "Types" Plugin are checked for the option "has archive".

    http://wordpress.org/extend/plugins/types/

  2. mbigul
    Member
    Plugin Author

    Posted 1 year ago #

    Dear User45,

    It is a WordPress behavior. Please add following code in your functions.php of theme to add custom post types to tag & category archives.

    <br />
    if ( ! function_exists( 'include_custom_post_types' ) ) {<br />
    function include_custom_post_types( $query ) {<br />
    if ( ! is_preview() && ! is_admin() && ! is_singular() ) {<br />
    $args = array(<br />
    'public' => true ,<br />
    '_builtin' => false<br />
    );<br />
    $output = 'names';<br />
    $operator = 'and';<br />
    $post_types = get_post_types( $args, $output, $operator );<br />
    $post_types = array_merge( $post_types, array( 'post' ) );<br />
    if ($query->is_feed) {<br />
    } else {<br />
    $my_post_type = get_query_var( 'post_type' );<br />
    if ( empty( $my_post_type ) )<br />
    $query->set( 'post_type', $post_types );<br />
    }<br />
    }<br />
    } }<br />
    add_action( 'pre_get_posts', 'include_custom_post_types' );<br />

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]

  3. kelsey.rahenkamp
    Member
    Posted 4 months ago #

    I am having the same problem! Does it matter where in my functions.php file I put the above code?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.