Skip Navigation

[Résolu] Display two different CPT on same page

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created Il y a 7 années et 11 mois. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 -
- - - - - - -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 5 réponses, has 2 voix.

Last updated by Adriano Il y a 7 années et 11 mois.

Assigned support staff: Adriano.

Auteur
Publications
#285757

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?

#285970

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?

#286080

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.

#286395

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

#286441

That worked perfectly. Thanks for your help.
Scott

#286447

You are welcome.

Le forum ‘Types Community Support’ est fermé à de nouveaux sujets et réponses.