• Resolved Nirmal Kumar

    (@onlinerockers)


    I have created a custom post type named ‘deals’. I tried many codes to add custom posts to my home feed. But they did not work.

    But adding some codes found on the internet, I added custom posts to the home page. But these posts are not shown in the home feed.

    This is my first problem. The following is the next one. I was able to create a search query in the feeds, for find my custom post type.

    I found that each post has an individual feed,

    But, when I click them I am getting 404 page. I am getting these 404 errors at Google Webmaster tools. Could you provide me a solution for this?

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

    (@tw2113)

    The BenchPresser

    Are you getting the 404 errors with the CPT feeds before or after your attempted changes that you mention at the start? Curious if you are maybe accidentally undoing things for those feeds, that were working at first.

    What customizations did you add as a whole, you never mention what you did. I have to believe pre_get_posts filtering would work, with a little bit of testing.

    Thread Starter Nirmal Kumar

    (@onlinerockers)

    Here is the complete set of codes I have added for various purposes.

    <?php
    function custom_conference_in_home_loop( $query ) { if ( is_home() && $query->is_main_query() ) $query->set( ‘post_type’, array( ‘post’, ‘deals’) ); return $query; } add_filter( ‘pre_get_posts’, ‘custom_conference_in_home_loop’ );
    ?>
    <?php
    function search_filter($query) {
    if ( !is_admin() && $query->is_main_query() ) {
    if ($query->is_search) {
    $query->set(‘post_type’, array( ‘post’, ‘deals’) );
    }
    }
    }

    add_action(‘pre_get_posts’,’search_filter’);
    ?>
    <?php
    function my_cptui_add_post_types_to_archives( $query ) {
    // We do not want unintended consequences.
    if ( is_admin() || ! $query->is_main_query() ) {
    return;
    }

    if ( is_category() || is_tag() && empty( $query->query_vars[‘suppress_filters’] ) ) {

    // Replace these slugs with the post types you want to include.
    $cptui_post_types = array( ‘deals’, ‘shopping-deals’ );

    $query->set(
    ‘post_type’,
    array_merge(
    array( ‘post’ ),
    $cptui_post_types
    )
    );
    }
    }
    add_filter( ‘pre_get_posts’, ‘my_cptui_add_post_types_to_archives’ );
    ?>

    I am getting this 404 error, even after removing all these codes.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hmm, not seeing anything obvious that would cause the 404 errors.

    Do you have your post types to have archives? Possible that that’s important in order to generate the feeds.

    Thread Starter Nirmal Kumar

    (@onlinerockers)

    Thanks, Michael . That was the error. I had set them to False. Now, feeds are working.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Awesome. It’s always the little details that trip us up. Glad to things are working now.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘404 error with feeds for custom post type’ is closed to new replies.