I have the next situation with my real estate site. I have different taxonomy's. I also use them for nested views. And i have taxonomy archive pages, with the next "construction":
Taxonomy: Broker (used with cpt broker and cpt real estate project for nested view)
Taxonomy: Developer (used with cpt broker and cpt real estate project )
Taxonomy: Place (used only with cpt project)
I have the next views:
1) Taxonomy place (taxonomy is set by current page) - Terms of the taxonomy places
2) Taxonomy developer (taxonomy is set by current page) - Terms of the taxonomy devolpers
3) Taxonomy broker (taxonomy is set by current page) - Terms of the taxonomy brokers
4) Parant view place (Places are the same as current single page) - Post projects
5) Parant view developer (Places are the same as current single page) - Post projects
6) Parant view broker (Places are the same as current single page) - Post projects
If i create a archive page bij a view, to show the projects of a place, broker and developer:
1) [wpv-view name="taxonomy-broker"]
2) [wpv-view name="taxonomy-place"]
3) [wpv-view name="taxonomy-developer"]
I't looks like the only taxonomy place is working correct. The other two developer and broker are not. These to are used by two ctp types the good one is not. Only the first results look to work. And then comes 1 in a row who displays more - not correct - results
Also, if i look in the taxonomy in the discripions the number of items that are assigned to them, it looks like there is one extra item with every taxonomy?
This also hapens only to the taxonomy broker and developer.
What am i missing?
Dear arnoldd,
Could you duplicate same problem in a test site, and fill below private detail box with login details, also point out the problem page URL and problem view URL, I need a live website to test and debug this problem, thanks
Thanks for the details, I can log into your website, will feedback if there is any found
I suggest we check the problems one by one
1) the problem page:
hidden link
Which is a archive page of term "heijmans-vastgoed"
Are you using the normal view "Taxonomy Nieuwbouw Ontwikkelaar" to output above archive page?
hidden link
If it is, it will conduct some unexpected result, I suggest you try style the archive page with Views wordpress archive, see our document:
Customizing Archive Pages with WordPress Archives:
https://toolset.com/documentation/user-guides/normal-vs-archive-views/
Hello Luoy,
Indeed i am using the normal view for the archive page. Same for the other archive page Partij.
So this "normal" method will not work? The rusults are indeed unexpected. I could not explain them.
Today i will convert them to View wordpress archive. I let you know the rusult.
I see what is happening now. I have made a view archive "ontwikkelaar"
Now the output for all the taxonomy "ontwikkelaar" is correct.
Beside: the View archive is also putting out / connecting a CPT in the taxonomy archive results.
This is the CPT i use for a nested view on the CPT "project" pages. In this case "betrokken partij" On heijmans for example: it puts out the taxonomy en also the related CPT betrokken partij Heijmans.
I expect this problem will also happens with the taxonomy "partijen". It's also related with the CPT "betrokken partijen" by a nested view.
So, the only thing i need now is to exclude the CPT "betrokken-partij" from al the view archive results.
Is this posible?
Yes, it is possible within WordPress action hook "pre_get_posts"
https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
see the demo codes in section "Exclude Pages from Search Results"
Luoy,
I don't get the "pre_get_posts" to work. Instead i am now using:
add_action( 'init', 'update_my_custom_type', 99 );
function update_my_custom_type() {
global $wp_post_types;
if ( post_type_exists( 'betrokken-partij' ) ) {
$wp_post_types['betrokken-partij']->exclude_from_search = true;
}
}
do you agree whit this?
I don't think it is a good idea to use the codes you mentioned above, and here is a similar thread, please check the solution in it, for your reference:
https://toolset.com/forums/topic/how-to-exclude-a-specific-custom-post-type-from-a-taxonomy-archive-loop/#post-207058
Thanks for the reply,
But if i use:
add_action( 'pre_get_posts', 'exclude_cpt' );
function exclude_cpt( $query ) {
if ( $query->is_tax('ontwikkelaar') ) {
$query->set( 'post_type', array('project') );
}
return $query;
}
to exclude cpt "betrokken-partij" on the taxonomy archive pages, this works also. Exept on the project pages where i use the taxonomy to display the taxonomy ontwikkelaar also, this code now breaks this.
If you log in you can see it.
I assume we are talking about this project pages:
hidden link
Could you point out where is break?
And I have modified your codes as below:
add_action( 'pre_get_posts', 'exclude_cpt' );
function exclude_cpt( $query ) {
if ( $query->is_tax('ontwikkelaar') && $query->is_main_query() ) {
$query->set( 'post_type', array('project') );
}
return $query;
}
Added && $query->is_main_query(), which will effect on the the main query of the tax archive page.
Luoy,
The break is that it has unexpected behavior. The fields don't show up(screenshot), or duplicate on the project page.
But the code with "&& $query->is_main_query()" is right now. Exept one more thing. I also need this code for the "partij" archive pages.
If i change the code to:
add_action( 'pre_get_posts', 'exclude_cpt' );
function exclude_cpt( $query ) {
if ( $query->is_tax('partij') && $query->is_main_query() ) {
$query->set( 'post_type', array('project') );
}
return $query;
}
This works for the "partij" archive. Accept WordPress don't accept two of this same snippets.
I suggest you try with different function name, for example:
add_action( 'pre_get_posts', 'exclude_cpt_partij' );
function exclude_cpt_partij( $query ) {
if ( $query->is_tax('partij') && $query->is_main_query() ) {
$query->set( 'post_type', array('project') );
}
return $query;
}
add_action( 'pre_get_posts', 'exclude_cpt_ontwikkelaar' );
function exclude_cpt_ontwikkelaar( $query ) {
if ( $query->is_tax('ontwikkelaar') && $query->is_main_query() ) {
$query->set( 'post_type', array('project') );
}
return $query;
}
Luoy,
This is it. I think you are done now. THANKS for your help!