Skip Navigation

[Resolved] toolset_get_related_posts with post_status

This support ticket is created 6 years, 2 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.

Our next available supporter will start replying to tickets in about 0.22 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 3 replies, has 2 voices.

Last updated by Nigel 6 years, 2 months ago.

Assisted by: Nigel.

Author
Posts
#1120692

I am trying to:
Trying to retrieve CPT child posts of parent CPT created via toolset, by using "toolset_get_related_posts".
And those child posts are submitted via the CRED form setting post_status as "pending".
So I need to specify post_status=any or pending together with "toolset_get_related_posts",
I think by default only status of "published" will be return though.
Link to a page where the issue can be seen:
hidden link
I don't know how to set post_status parameter in "toolset_get_related_posts", which is easier than using
get_posts function as below.
$child_posts = get_posts(array(
'numberposts' => -1,
'orderby' => 'name',
'post_type' => 'event-application',
'post_status' => 'any',
'meta_query' => array(
array(
'key' => '_wpcf_belongs_event-and-seminar_id',
'value' => get_the_ID(),
'compare' => '=',
),
),
));

#1120787

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi there

Can you first clarify, the related posts are Types 2 relationships, migrated Types 2 relationships, or relationships created with Types 3?

If you go to Toolset > Relationships are you asked to run the migration wizard, or can you add and edit relationships?

#1120801

Hi Nigel,

I think I created this relationships via Types 2, and after that I have upgraded to Types 3.

I found Toolset > Relationships menu, and found a "Run the migration" button. However I have not tried it run migration yet. Is it better to run the migration before further coding? (Of course after the DB dump)

Thanks.

#1121560

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

I would suggest running the migration, except toolset_get_related_posts doesn't have any arguments for specifying the post status of the posts you wish to return.

So you may be better of sticking with the site as it is (the Types 2 relationships), where you can use get_posts and where the parent is specified in a meta query.

If you need features from Types 3 relationships, such as genuine many-to-many relationships, then you would need to run the migration.

In that case you could use toolset_get_related_posts to get the child posts, but then you would have to loop over them and discard any that did not have the required status.