I have a site with two custom post types - one is for testimonies, and the other to list affiliated partners. The testimonies I have set up in a View, which are being displayed in the site's Primary sidebar. It displays just as I am expecting it to on every page, except for the archive page of the affiliate partner custom post type.
This page displays the testimonies correctly on the right side in a rotating "banner": hidden link
You can see how I want it to look in this screenshot: hidden link
This page displays all the testimonies at once, and does not rotate as expected: hidden link
You can see the issue in this screenshot hidden link
Is there a reason why the view won't work on the same page as a CPT archive page?
Hi Scott,
I've tried to reproduce the same environment on my localhost, but I couldn't reproduce that issue. First thing I'd recommend you is to isolate that problem:
1. Disable any other plugin
2. Select a default WordPress theme
3. Test again
It'll help us to understand if there is some compatibility issue with any site's element.
In case the issue is still there, I'd recommend you to give me the exact steps to reproduce that. The main thing that I need is your View information. Could you attach an image from it?
I figured out the source of the problem, but I still think I need some assistance solving the issue.
I'm using a function to display all the "Affiliates" on the archive page in alphabetical order by title:
function set_cpt_archive_page( $query ) {
// Show all Affiliate results on archive page
if(is_post_type_archive('affiliates')) {
$query->set( 'posts_per_page', -1 );
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
return;
}
}
add_action( 'pre_get_posts', 'set_cpt_archive_page' );
This is correctly displaying all the affiliates on the archive page, but it is also causing all of the Testimonials to be displayed when viewed on the affiliates archive page.
I guess I need to modify this function to only apply to the affiliates, and leave the testimonials alone.
Hi Scott,
You can try that:
function set_cpt_archive_page( $query ) {
// Show all Affiliate results on archive page
if(($query->is_archive() && (get_post_type() == 'affiliates')) {
$query->set( 'posts_per_page', -1 );
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
return;
}
}
add_action( 'pre_get_posts', 'set_cpt_archive_page' );
Please let me know if you are satisfied with my reply and any other questions you may have.
Regards,
Adriano Ferreira
That worked perfectly. Thanks for your help.
Scott