2

I created a custom post type

function faq_func() {

$labels = array(
    'name'                => _x( 'FAQs', 'Post Type General Name', 'rrrrr' ),
    'singular_name'       => _x( 'FAQ', 'Post Type Singular Name', 'rrrrr' ),
    'menu_name'           => __( 'FAQ', 'rrrrr' ),
    'parent_item_colon'   => __( 'Parent Item:', 'rrrrr' ),
    'all_items'           => __( 'All Items', 'rrrrr' ),
    'view_item'           => __( 'View Items', 'rrrrr' ),
    'add_new_item'        => __( 'Add New', 'rrrrr' ),
    'add_new'             => __( 'New Item', 'rrrrr' ),
    'edit_item'           => __( 'Edit Item', 'rrrrr' ),
    'update_item'         => __( 'Update Item', 'rrrrr' ),
    'search_items'        => __( 'Search Item', 'rrrrr' ),
    'not_found'           => __( 'No items found', 'rrrrr' ),
    'not_found_in_trash'  => __( 'No items found in Trash', 'rrrrr' ),
);
$rewrite = array(
    'slug'                => 'faq',
    'with_front'          => true,
    'pages'               => false,
    'feeds'               => false,
);
$args = array(
    'label'               => __( 'faqs', 'rrrrr' ),
    'description'         => __( 'FAQ Page', 'rrrrr' ),
    'labels'              => $labels,
    'supports'            => array( 'title', 'editor', ),
    'hierarchical'        => false,
    'public'              => true,
    'show_ui'             => true,
    'show_in_menu'        => true,
    'show_in_nav_menus'   => true,
    'show_in_admin_bar'   => true,
    'menu_position'       => 5,
    'menu_icon'           => get_bloginfo('template_directory').'/images/faq-icon.png',
    'can_export'          => true,
    'has_archive'         => true,
    'exclude_from_search' => true,
    'publicly_queryable'  => true,
    'query_var'           => 'faq',
    'rewrite'             => $rewrite,
    'capability_type'     => 'page',
);
register_post_type( 'faqs', $args );

}

add_action( 'init', 'faq_func', 0 );

And a archive-faqs.php file:

<?php get_header(); ?>

<?php
$args = array( 'post_type' => 'faqs' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
    the_title();
    echo '<div class="entry-content">';
    the_content();
    echo '</div>';
endwhile;
?>

<?php get_footer(); ?>

The problem is that my items not visible on the page. Where is the problem?

UPDATE: I found the solution on wordpress.org:

Note: In some cases, the permalink structure must be updated in order for the new template files to be accessed when viewing posts of a custom post type. To do this, go to Administration Panels > Settings > Permalinks, change the permalink structure to a different structure, save the changes, and change it back to the desired structure.

  • Your title implies that the CPT single/archive template files aren't being used, but in your question you indicate that the problem is that terms aren't being displayed. Which is it? And if the problem is that terms aren't being displayed, you'll need to include the template code that you expect to output those terms. – Chip Bennett Oct 25 '13 at 12:15
  • Also: why are you creating a custom query loop in archive-faqs.php? – Chip Bennett Oct 25 '13 at 12:16
  • I would like to list only the content and the title what I add under the FAQ cpt. I don't use terms/taxonomies. I replaced the query <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <h1 class="title"><?php the_title(); ?></h1> <?php the_content(); ?> <?php endwhile; else: ?> <p><?php _e('No posts were found. Sorry!'); ?></p> <?php endif; ?> with this but it's not working. – user1452062 Oct 25 '13 at 12:46
  • That's fine. The issue is this: $loop = new WP_Query( $args );. Why are you doing that? It essentially stomps on the default WordPress query - which is ostensibly the very query you want to loop through/output. – Chip Bennett Oct 25 '13 at 12:50
  • I copied that from wordpress.org. Now I'm using the default query in the archive-faqs.php but it's not working. – user1452062 Oct 25 '13 at 13:15