• chicchera

    (@chicchera)


    I am trying to add custom post types and cannot find how to do it. I have registered a post type but don’t seem to ever be able to access it.

    As a matter of fact, I could do with a simple add_filter(‘the_content’,’whatever…’), but also this doesn’t seem to work.

    Where should I start form?

    thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Theme Author presscustomizr

    (@nikeo)

    Hi, the add_filter (‘content’, …) approach will not work properly.
    You might want to start by using the WordPress template hierarchy (with a copy of index.php file) or with these snippets for a more advanced developer approach : change the WordPress query.
    Hope this helps and enjoy the theme

    @ chicchera

    I’ve just spent the last 3 days banging my head against the keyboard.
    Assuming you have a child theme and you registered properly the CPT and you see them in the dashboard, I did some renaming here and there to be able to see and use theme front-end. here is the list:

    1) make a copy index.php and rename it into single-yourCPTname.php
    2) make a copy index.php and rename it into archive-yourCPTname.php

    1 makes your single CPT visible
    2 makes your CPTs in a list

    Depending on how you created your CPT (with custom taxonomy or standard, etc) this “old” snippet below helps to integrate your CPT with all the other WP elements;
    paste this into your functions.php

    //Add Custom Post Types to Tags and Categories in WordPress
    
    function add_custom_types_to_tax( $query ) {
    if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
    
    // Get all your post types
    $post_types = get_post_types();
    
    $query->set( 'post_type', $post_types );
    return $query;
    }
    }
    add_filter( 'pre_get_posts', 'add_custom_types_to_tax' );
    //https://premium.wpmudev.org/blog/add-custom-post-types-to-tags-and-categories-in-wordpress/
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom post types’ is closed to new replies.