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?
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?
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?
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.
My issue is resolved now. Thank you!