Skip Navigation

[Resolved] Access data in post reference field

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 2 replies, has 2 voices.

Last updated by Khurram 5 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1162126

Tell us what you are trying to do?

I am trying to access data of post reference field in functions.php using legacy get_post_meta function. I am update field using toolset forms (cred).

I tried to follow this thread as well;

https://toolset.com/forums/topic/how-do-access-the-data-stored-for-a-entry-in-a-post-reference-field-using-php/

 $memberid = get_post_meta( $assemblyid, "wpcf-member", true);
echo "Post ID: " . $memberid; 

The above code is not working. Please help and better to mention details that how post reference field is saved in database when saved from Admin, and how differently it is saved in database when saved using frontend froms (cred).

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#1162479

I am update field using toolset forms (cred).
Hi, the reference post field value is the same, whether it is modified in a front-end Form or in wp-admin. I can't see in your code how $assemblyid is defined. First, please echo $assemblyid and confirm it is the correct post ID (it should be the ID of the post that contains the reference field).

echo "Assembly ID: " . $assemblyid . "<br />";
$memberid = get_post_meta( $assemblyid, "wpcf-member", true);
echo "Post ID: " . $memberid; 

If the Assembly ID is incorrect, then you have a problem in another part of your code. You should also confirm that your post reference field slug is "member" in wp-admin. The prefix "wpcf-" should not be added in wp-admin, though it is required in functions.php. If you are still not getting the results you expected, please copy + paste the code from your Form here for me to review.

#1162717

Hi Christian,

Thanks for your answer. I tried this method already but it didn't worked as wp_postmeta does not contains a meta_key for 'wpcf-member'.

I found out that reference field values are not getting stored in wp_postmeta anymore.

I went into table wp_toolset_relationships and find out that there is a relationship in "slug" column with value 'member' and "origin" column contains value 'post_reference_field'.

Then I went into wp_toolset_associations table and find out that post-reference value (member in this case) was stored in 'parent_id' column and assembly_id was stored in 'child_id' column.

I used following code to find out post reference value and it worked.

		$member_id = toolset_get_related_post( $assemblyid, 'member', 'parent' );

Post reference relationship is not visible in Relationships menu of toolset. I suggest to include post reference relationships in a separate tab of Relationships, as well as please update the documentation.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.