• Resolved ergkranjan

    (@ergkranjan)


    Hi Team,

    I am using customizr theme. Its best theme for me at least.
    I have implemented a custom post type for a tutorial series. I am using Types Plugin for that. Everything working fine but when I click on the date link of archive, its giving me page not found error. Also these posts are not coming in search result and in author archive. These posts are also not been added in month archive.

    Can you please help on this.

Viewing 15 replies - 1 through 15 (of 22 total)
  • Hello,
    I’m just testing that plugin. And..
    1) my custom post type’s top is shown in the search results. Is your custom post type querable?
    publicly_queryable (checked)
    Whether post_type queries can be performed from the front end.
    Default: value of public argument.
    exclude_from_search (unchecked)
    Whether to exclude posts with this post type from search results.
    Default: value of the opposite of the public argument.

    2) To show cpt in post lists you might want to add this to your child-theme functions.php:
    add_filter('tc_include_cpt_in_archives', '__return_true');

    Should work.

    Thread Starter ergkranjan

    (@ergkranjan)

    Hi Friend,

    Thanks for your prompt response.

    I have a setting as you want but still i am not able to get mu custom posts in search result.
    I also want to display my custom posts with regular posts in latest posts and in archive.

    Please help me on this.

    Can you try the step 2?

    Thread Starter ergkranjan

    (@ergkranjan)

    I tried it but could not get any solution.
    I am able to see my custom post in category and in tags (taxonomy allowed in custom post), but not able to see in archive and in search.

    Thread Starter ergkranjan

    (@ergkranjan)

    After adding this line
    add_filter(‘tc_include_cpt_in_archives’, ‘__return_true’);

    In archive, i am getting each and every thing for example, pages, categories addition etc.

    I just want to add my custom post type, not pages.

    Thanks.

    mm, weird , works here once I add that line in my child-theme functions.php

    What’s the content of your child-theme functions.php?

    Thread Starter ergkranjan

    (@ergkranjan)

    <?php
    add_action( ‘wp_enqueue_scripts’, ‘theme_enqueue_styles’ );
    function theme_enqueue_styles() {
    wp_enqueue_style( ‘parent-style’, get_template_directory_uri() . ‘/style.css’ );
    wp_enqueue_style( ‘child-style’, get_stylesheet_directory_uri() . ‘/style.css’, array(‘parent-style’)
    );
    }

    //Add search box
    // As of 3.1.10, Customizr doesn’t output an html5 form.
    add_theme_support( ‘html5’, array( ‘search-form’ ) );

    add_filter(‘wp_nav_menu_items’, ‘add_search_form_to_menu’, 10, 2);
    function add_search_form_to_menu($items, $args) {

    // If this isn’t the main navbar menu, do nothing
    if( !($args->theme_location == ‘main’) )
    return $items;

    // On main menu: put styling around search and append it to the menu items
    return $items . ‘<li class=”my-nav-menu-search”>’ . get_search_form(false) . ”;
    }

    ?>

    Thread Starter ergkranjan

    (@ergkranjan)

    Displaying custom posts in archive is working but its also displaying all taxonomies and created pages with posts. Also search functionality is not working, even I have all set as you suggested.

    Thread Starter ergkranjan

    (@ergkranjan)

    In search result also, custom posts are not coming.

    Ah I see.
    About the search I don’t know works fine here :/
    About displaying taxes and pages when using that code, yeah is something wrong. Must be fixed.
    But with taxonomies you mean custom taxonomies?

    Thread Starter ergkranjan

    (@ergkranjan)

    Hi Friend,

    Thanks for your help. It was my bad. I have used Relavansi for search and I forgot to include my custom post type there.

    But the archive problem is still there. Here is some more detail:

    1. When i click on date link of custom post type, its giving me page not found error.

    2. Custom post type is not displaying in author and month archive.

    Please help me on these points.

    Try using this:

    add_action( 'pre_get_posts', 'include_cpt_in_archives', 100);
    function include_cpt_in_archives( $query ){
      if (
            is_admin()
            || ! $query->is_main_query()
            || ! ( $query->is_search || $query->is_archive )
        )
        return;
    
      $post_types = get_post_types( array('public'=> true, 'exclude_from_search'=> false, '_builtin' => false) );
      // add normal post
      $post_types['post'] = 'post';
    
      $query -> set('post_type', $post_types);
    }

    ’cause 1 and 2 are about the same problem.

    Let me know

    Thread Starter ergkranjan

    (@ergkranjan)

    Hi Friend,
    Great support thanks. Its working fine now.

    You are hero of the day for me.

    Just one more question related to this topic, can i also add the count of custom post in archive and get them in list of that month on clicking on the month name.

    Thread Starter ergkranjan

    (@ergkranjan)

    Hi Friend, Sorry for this. After adding the above code, I am getting all custom posts in my archive lists also.

    Thanks for your support.

    I also added below line to show the count in month archive.

    add_filter( ‘getarchives_where’, ‘custom_getarchives_where’ );
    function custom_getarchives_where( $where ){
    $where = str_replace( “post_type = ‘post'”, “post_type IN ( ‘post’, ‘post-type-mypost’ )”, $where );
    return $where;
    }

    Thread Starter ergkranjan

    (@ergkranjan)

    I am closing this topic as resolved.

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘Custom post type in Search and Author Archive and Date Archive’ is closed to new replies.