Skip Navigation

[Resolved] Display posts by same author with Gridbuilder WP

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 year, 3 months ago.

Assisted by: Minesh.

Author
Posts
#2627843

Ian

Tell us what you are trying to do?
I am trying to display a Gridbuilder WP grid showing posts by the same author of the current post

Is there any documentation that you are following?
I was looking at this response to another user https://toolset.com/forums/topic/display-relationship-post-with-gridbuilder-wp/
I am actually also switching from "the grid" to Gridbuilder WP".

Is there a similar example that we can see?
[code]
function my_query_args($query_args, $id) {

if ($id === 1) {

global $post;

$related_posts = toolset_get_related_posts( $post->ID, 'go', array( 'query_by_role' => 'parent', 'limit' => 999, 'return' => 'post_id', 'role_name_to_return' => 'other' ) );

$query_args['post__in'] = $related_posts;
}

return $query_args;

}
add_filter('wp_grid_builder/grid/query_args', 'my_query_args', 10, 2);
[/code]

What is the link to your site?
hidden link
This is currently showing content from the grid plugin

#2627931

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

I checked the following page you shared:
- hidden link

Within what section you are trying to display the content using the "gridbuilder wp"? what content you want to display that is belongs to the author of the same post?

Have you added any hook that you shared as reference with your initial post "wp_grid_builder/grid/query_args"?

I will need admin access details and once I will review your current settings I will be able to guide you in the right direction.

*** 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.

#2631653

Minesh
Supporter

Languages: English (English )

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

Can you please check now: hidden link

I've adjusted the code to your code snippet as given under:
=> hidden link

function grid_query_related_author_posts( $query_args, $grid_id ) {

	global $post;
	
	// If it does not match grid id 1.
	if ( 7 !== $grid_id ) {
		return $query_args;
	}

/*	$taxonomy = 'category'; // You have to change "category" to the associated taxonomy.
	$post_id  = wp_doing_ajax() ? url_to_postid( wp_get_referer() ) : $post->ID;
	$terms    = get_the_terms( $post_id, $taxonomy );

	if ( is_wp_error( $terms ) || empty( $terms ) ) {
		$query_args['post__in'] = [ 0 ];
	} else {

		$query_args['post__not_in'] = [ $post_id ];
		$query_args['tax_query']    = [
			[
				'taxonomy' => $taxonomy,
				'terms'    => wp_list_pluck( $terms, 'term_id' ),
			],
		];
	}
	*/
  $query_args['author__in'] = [ $post->post_author ];
  
  

	return $query_args;

}
add_filter( 'wp_grid_builder/grid/query_args', 'grid_query_related_author_posts', 10, 2 );

Can you please confirm it works as expected now.