• Resolved michaelpiercy

    (@michaelpiercy)


    Hi Everyone,

    I’m wondering if anyone else is having trouble with basic Custom Post Types using 3.9? I can add the Custom Post Type using the code below with no problems but none of the posts are actually listing in their relative category feeds. Maybe I’m missing a step or something here.

    I had it set up on an another site using 3.8x but I can’t seem to get it working on any new build attempts.

    Here’s a link to the basic test build: rings.midasselect.om

    Below is the basic code I’m using in functions.php to create the custom post type example. Any advice appreciated.

    Cheers,

    Michael

    <?php
    
    // Add Product Post Type
    
    add_action( 'init', 'create_post_type' );
    function create_post_type() {
        $labels = array(
            'name' => __( 'Products' ),
            'singular_name' => __( 'Product' ),
          );
    
        register_post_type( 'acme_product',
            array(
                'labels' => $labels,
                'public' => true,
                'has_archive' => true,
                'taxonomies' => array('category'),
                )
            );
    }
    
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • I believe that the archives page only includes the default post post type. Take a look at this article on how to add the custom post types so that the template will display them.

    Ashley

    Thread Starter michaelpiercy

    (@michaelpiercy)

    Thanks Ashley,

    I took a look and tried out the code in the link you gave but to no avail. I don’t mind changing my strategy here if there’s another way to do this? I just don’t want to have to use a plugin for it…

    Below is what my functions.php looks like now that I added products post type… Any more ideas? It’s really bugging me!

    <?php
    
    // Add Product Post Type
    
    add_action( 'init', 'create_post_type' );
    function create_post_type() {
        $labels = array(
            'name' => __( 'Products' ),
            'singular_name' => __( 'Product' ),
          );
    
        register_post_type( 'acme_product',
            array(
                'labels' => $labels,
                'public' => true,
                'has_archive' => true,
                'taxonomies' => array('category'),
                )
            );
    }
    
    function namespace_add_custom_types( $query ) {
      if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
        $query->set( 'post_type', array(
         'post', 'products'
    		));
    	  return $query;
    	}
    }
    add_filter( 'pre_get_posts', 'namespace_add_custom_types' );
    
    ?>
    Thread Starter michaelpiercy

    (@michaelpiercy)

    Oh, I got it. Actually the code you gave did work, Ashley. I was just placing the wrong array in to the list of post types.

    For anyone else that has trouble with this, be sure to put in the exact same string that was passed as a parameter to your register_post_type function.

    Thanks again Ashley!

    Michael

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