Ask your WordPress questions! Pay money and get answers fast! (more info)

Why are my CPT post not showing up in ANY archive?

  • SOLVED

I'd like someone to have a look at my theme and find out why (and tell me why) none of my CPT posts are not showing up in any archive loop. I'm happy to give out my ftp details however you need to have a good history here on wp questions.


Thanks everyone... first in first served :)

Answers (5)

2014-07-18

Navjot Singh answers:

PM me your FTP details.


pjeaje comments:

semicolon theme


pjeaje comments:

Navjot Singh is trying first

2014-07-18

Sabby Sam answers:

Hi Pieaje,
When you create CPT there are option into. You must check in your code first and I guess this will help you http://codex.wordpress.org/Function_Reference/register_taxonomy. If it doesn't resolve please pm me the details I will get it resolve asap.

2014-07-18

Bob answers:

have you tried creating archive template for your cpt?


Bob comments:

can you post you link here or provide me access to your theme?


pjeaje comments:

It doesn't even show the posts in author.php


Bob comments:

is it showing category, tag or month archive?


Bob comments:

Archives.php only shows content of type 'post', but you can alter it to include custom post types. Add this filter to your functions.php file:


function namespace_add_custom_types( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array(
'post', 'your-custom-post-type-here'
));
return $query;
}
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types' );


note replace <strong>your-custom-post-type-here</strong> with your post type.


pjeaje comments:

Yeah i've done that already


Bob comments:

I also assume you already added ‘publicly_queryable’ => true, to the $args array of your CPT.
then make your cpt available in search you need to put this code in your theme's functions.php file


// Define what post types to search
function searchAll( $query ) {
if ( $query->is_search ) {
$query->set( 'post_type', array( 'post', 'page', 'feed', 'custom_post_type1', 'custom_post_type2'));
}
return $query;
}

// The hook needed to search ALL content
add_filter( 'the_search_query', 'searchAll' );

Replace <strong>custom_post_type1</strong>, <strong>custom_post_type2</strong> with your CPT.


Bob comments:

Then without examining code it is difficult to find problem! are you working in localhost?
have you created archive template? if yes is it working properly?
if no you can create archive-{posttype}.php file in theme and test if custom posts are visible there or not.

2014-07-18

Luis Abarca answers:

Are you using custom taxonomies or the built-in categories of WordPress ??


pjeaje comments:

CPT = custom post type


Luis Abarca comments:

If you want to mix posts and custom post types, you can use a filter like this one:


function add_cpt_to_loop( $query )
{
if ( $query->is_main_query() ) { // you can also check por archive or specific category here
$query->set( 'post_type', array( 'post', 'your_custom_post_type') );
}

return $query;
}

add_filter( 'pre_get_posts', 'add_cpt_to_loop' );

2014-07-18

timDesain Nanang answers:

<blockquote>Bob says:
I also assume you already added ‘publicly_queryable’ => true, to the $args array of your CPT.
then make your cpt available in search you need to put this code in your theme's functions.php file</blockquote>


try: put this code

add_action( 'pre_get_posts', 'wpq_add_post_types_to_query' );

function wpq_add_post_types_to_query( $query ) {
if ( !is_admin() ){
if ( $query->is_main_query() ) //post archive
$query->set( 'post_type', array( 'post', 'property-for-sale' ) );
elseif( $query->is_author) //author.php
$query->set( 'post_type', array( 'property-for-sale' ) );
elseif($query->is_date) // archive by date
$query->set( 'post_type', array( 'post', 'property-for-sale', 'another_cpt', ) );
//is_search
//is_category
//is_tax
}
return $query;
}


codex: http://codex.wordpress.org/Conditional_Tags