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

Genesis custom post type loop not working properly WordPress

  • SOLVED

I have a custom genesis theme and have a custom post type created.

This is what I've done.


remove_action('genesis_loop', 'genesis_do_loop');

add_action( 'genesis_loop', 'child2_do_custom_loop' );

function child2_do_custom_loop() {
global $paged; // current paginated page
global $query_args; // grab the current wp_query() args
$args = array(
'paged' => $paged, // respect pagination
'post_type' => 'travel_alert',
);

genesis_custom_loop( wp_parse_args($query_args, $args) );

}


The problem is, when I try to view an archive of the custom taxonomy it just lists all the posts regardless of category.

I first tried it with default categories, then tried with custom taxonomy.

/travel_alert/type/cheap-flights/
/travel_alert/type/hotels

They both just list all posts from every category.

I've tried

$recent = new WP_Query("post_type=travel_alert"); while($recent->have_posts()) : $recent->the_post();


So basically I can only view all posts, or a single post, but unable to view by category. I have not changed anything else related to the loop. Simply removed the default loop, added a custom one that queries the post type.

Any suggestions?

Answers (3)

2013-02-26

Arnav Joy answers:

try using this:-

remove_action('genesis_loop', 'genesis_do_loop');



add_action( 'genesis_loop', 'child2_do_custom_loop' );



function child2_do_custom_loop() {

global $paged; // current paginated page

global $query_args; // grab the current wp_query() args

$args = array(

'paged' => $paged, // respect pagination

'post_type' => 'travel_alert',

'cat' => get_query_var('cat')
);



genesis_custom_loop( wp_parse_args($query_args, $args) );



}


Dan | gteh comments:

Just tried that, doesn't work either. still pulling in all posts.


Arnav Joy comments:

are you sure , your code is working

try this to insure that.

remove_action('genesis_loop', 'genesis_do_loop');



add_action( 'genesis_loop', 'child2_do_custom_loop' );



function child2_do_custom_loop() {

echo 'test';exit;
}


Dan | gteh comments:

it echos "test".

I must have made a typo before. It is working now that I have added

'cat' => get_query_var('cat')


Thanks

2013-02-26

Kyle answers:

Did you try replacing the default content also?

remove_action( 'genesis_post_content', 'genesis_do_post_content' );

[[LINK href="http://www.wpsquare.com/create-custom-archives-page-genesis-theme/"]]http://www.wpsquare.com/create-custom-archives-page-genesis-theme/[[/LINK]]


Dan | gteh comments:

That is only if I want to create a custom archive page.

I want to always query my custom post type. So visiting /category/cat-name should display all posts in that category only within my custom post type. Instead what's happening is it is listing ALL posts from ALL categories within my custom post type.

So I'm removing the loop, and replacing it with a custom loop that queries my custom post type. that part works, it just won't honor the category/custom taxonomy listing.


Kyle comments:

Ah I see, I believe Arnav's code below would work then where you pull the current category into your custom query

2013-02-26

Martin Pham answers:

please try this code

remove_action('genesis_loop', 'genesis_do_loop', 5);
add_action( 'genesis_loop', 'child2_do_custom_loop' );
function child2_do_custom_loop() {
//$post_type = get_query_var('post_type'));
$query_args = array(
'post_type' => 'post_type',
'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1,
'posts_per_page' => get_option( 'posts_per_page' )
);
genesis_custom_loop( $query_args );
}