Skip Navigation

[Resolved] adding information from other posts to current post

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by Minesh 1 month ago.

Assisted by: Minesh.

Author
Posts
#2778811
sample post.jpg

Hi, I have a book review site with custom posts named All Fiction in those posts are custom fields and standard WordPress fields what I want to do is at the bottom of any book review show a list of all the authors' other books along with thumbnails of the other books. The Book Title is the Post Title and the author name is a custom field named Author (the slug is writer). my question is how do I pull the other books from the custom posts by the same author in the All Fiction Posts onto the currently viewed posts page

I have been through views and relationships and can't find anything that helps

The link to the website is hidden link

#2778821

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

You can create a view and set this view to query your post type "All Fiction":
=> https://toolset.com/course-lesson/creating-a-view/

And add a Query Filter to your view for the post author and you can select the option post author is the author of the current post.
- https://toolset.com/documentation/legacy-features/views-plugin/filtering-views-query-by-author/#post-author-is-the-author-of-the-page-where-this-view-is-shown

if that does not help, please feel free to share problem URL and admin access details with your expected result.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2779355

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now: hidden link

With the single post content template for your post type "All Fiction" I've added the view block "book-author-posts":
- hidden link

You can design the view's loop as required.

And with the "Custom code" section offered by Toolset, I've added the following "wpv_filter_query" hook in order to filter the posts with current post's custom field value namely "author":

add_filter( 'wpv_filter_query', 'func_current_post_custom_field_value', 99, 3 );
function func_current_post_custom_field_value( $query, $view_settings, $view_id ) {
  
  global $post;
  if ( $view_id == 27421 ) { 
    
     
    $meta_query = $query['meta_query'];
   
     if(empty($meta_query)){
       
     
       
       $target_field_name = 'wpcf-author';
       $author_field_value = get_post_meta($post->ID,$target_field_name,true);
      
       
       
       		if(!empty($author_field_value)){
       
       			$query['meta_query'][]  =  array('key' =>  $target_field_name,
                                    'type' => 'CHAR',
                                    'compare' => '=',
                                    'value' => $author_field_value
                                );
       		}else{
              	$query['post__in'] = array(0);
            }                     
     
       }
                         
  }
  
  
    return $query;
}

Can you please confirm it works as expected.

#2779504

Thank you Minesh that's exactly what I wanted now I can follow your example and add it to the other genries