Skip Navigation

[Resolved] Relationship API does not return all relationships even if relationship exists

This support ticket is created 3 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by himanshuS 3 years, 9 months ago.

Assisted by: Christian Cox.

Author
Posts
#1938447

I have an O2O post relationship between two post types: endorsement request and endorsement.

I am able to form relationships between the posts by using the CRED form. (screenshot attached). But, when I try to retrieve the child posts that are related to the parent post, the function does not return some posts.

Video explaining the issue: hidden link

The video shows the following:
1) An endorsement request exists and has a child endorsement CPT
2) The endorsement CPT is published
3) The code that I am using to print child post ids using the toolset API
4) The API prints some IDs but not other ids. The ID in question is 13577 (for test).

The code works fine as it returns values for the current user. The code in details:

<?php global $wpdb;
global $post;

$current_post_type = get_post_type( );
$user_id = get_current_user_id();
if($current_post_type == 'portfolio' ) {
$user_id = $post->post_author;
}

$args = array(
'author' => $user_id,
'orderby' => 'post_date',
'order' => 'ASC',
'post_type' => 'endorsement-request',
'post_status' => 'publish'
);
$count =0;
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
// Do Stuff
$post_id_er = get_the_id();
$endorsement_id = toolset_get_related_post($post_id_er, 'endorsement-request-to-endorsement', 'child', 'publish');
If ($endorsement_id!=0)
{
$count = $count +1;
echo $endorsement_id;
echo 'break';
}
endwhile;
endif;
//echo $count;
// Reset Post Data
wp_reset_postdata();
?>

What could I be missing?

#1939561

Not sure if I can determine whether or not the WP_Query results include the parent Endorsement Request 13580 based on the information I have. The GIF is moving too fast for me to really read and follow along. If you echo the post_id_er temporarily, can you confirm that the Endorsement Request 13580 is included in the WP_Query results as expected?

$post_id_er = get_the_id();
echo ', test post ID: ' . $post_id_er . ', ';

Are the results on the front-end of the site identical to the results in the Elementor design builder?

#1939785

Christian,
The issue is resolved. The code did not like 'order' and 'orderby' in the same argument. I am not sure why because it still returned some rows earlier. Do you know what it could be?

Basically, this worked:
$args = array(
'author' => $user_id,
'post_type' => 'endorsement-request',
'post_status' => 'publish'
);

On another note, I have a lot of custom code in your custom code section, I was wondering if there is a way to see all custom on one page instead of pagination . Right now, it seems to have a limit of 20 queries. Can this be increased somewhere in settings?

New threads created by Christian Cox and linked to this one are listed below:

https://toolset.com/forums/topic/pagination-settings-in-toolset-settings-custom-code-tab/

#1939961

I am not sure why because it still returned some rows earlier. Do you know what it could be?
Maybe orderby 'date' instead of 'post_date'? Not sure offhand. Docs for WP_Query:
https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters

On another note, I have a lot of custom code in your custom code section, I was wondering if there is a way to see all custom on one page instead of pagination . Right now, it seems to have a limit of 20 queries. Can this be increased somewhere in settings?
Split this into a new ticket, I think there could be a problem with pagination settings in this screen.

#1940019

My issue is resolved now. Thank you!