Hi, i try to structure a toolset wordpress query that displays a specific taxonomy (A)+(B) of the post where it is executed and also the taxonomy (A)+(B) present in all the posts with the same title as the post being executed. How can I start setting up work? Thank you
Hello and thank you for contacting the Toolset support.
I am not really sure to understand your request, can you elaborate more? Are (A)+(B) your taxonomy terms? What do you mean by “the taxonomy (A)+(B) present in all the posts with the same title as the post being executed”
OK
My Taxonomy terms is: AIRCRAFTS and NICKNAMES
The query display this terms (of the post) and all of the post with the same title of the current post.
Thank you for your feedback. But I'll still need more details to understand your request, especially, all of the post with the same title of the current post. The more details you provide the quicker we'll find a way to help you.
Can you also give an example maybe as follow:
- Post1: has terms xxx from AIRCRAFTS and terms yyy NICKNAMES.
- Post2: ...
- Etc.
I would like to have page xxx to display yyy and zzz.
OK
- Post1 (title A): has terms xxx from AIRCRAFTS and terms yyy from NICKNAMES of post1 and post2 (same title).
- Post2 (title A): has terms xxx from AIRCRAFTS and terms yyy from NICKNAMES of post2 and post1 (same title).
- Post3 (title B): has terms xxx from AIRCRAFTS and terms yyy from NICKNAMES of post3 (because there are no other posts with the same title).
- Post4 (title C): has terms xxx from AIRCRAFTS and terms yyy from NICKNAMES of post4 (because there are no other posts with the same title).
Thank you for your feedback. I'll write what I have understood so far and please correct me if I am wrong.
You want to display on a post single page, the posts that have the same taxonomies terms and the same title, right? So, with your example, we will have:
- Post1 page will also display Post2
- Post2 page will also display Post1
- Post3 page will not display any additional posts.
- Post4 page will not display any additional posts.
Is this what you are trying to achieve?
In addition, I would like to know how you show a single post page? Using a content template? Using a layout? Or maybe you are trying to add the additional post with a view?
Can you also give examples of the URLs that you will have for your pages, that could help me understand better the structure and views that you are building?
I was able to create a similar view on my local setup with 4 posts.
First I created a view that is filtered with taxonomy terms related to the current post, check this screenshot hidden link
Then I integrated this view inside my Custom Post Content template. At this stage, the view shows all the posts that have the same AIRCRAFTS and NICKNAMES terms.
Then I had to add the following code to add a custom search on post title and only include the posts that have the same exact title, please note that you will need to adapt the view ID of the code with your View ID, check this screenshot hidden link
function func_search_by_exact_title( $search, $wp_query ){
global $wpdb;
global $WP_Views;
global $post;
if($WP_Views->current_view == 1065){
// if ( empty( $search ) )
// return $search; // skip processing - no search term in query
$current_post = get_post( $post->ID );
$term = isset( $current_post->post_title ) ? $current_post->post_title : '';
error_log(print_r(array("term" => $term, "current_post" => $current_post), true));
$search = " AND ($wpdb->posts.post_title REGEXP '[[:<:]]{$term}[[:>:]]')";
}
return $search;
}
add_filter( 'posts_search', 'func_search_by_exact_title', 1000, 2 );
This helped me show:
- Post 2 inside Post 1 as they have the same title "Title A", I have also added the Post ID to distinguish between them, check this screenshot hidden link
- Post 4 has no additional posts because no other post has the title "Title C", check this screenshot hidden link