0

I've a few post that have ACF relationship field set up :

- Post A
- Post A1
- Post A2
- Post A3

Post A have a relationship that link to : Post A1,A2 & A3...

Post A1,A2,A3 have their own post templates,

But inside the post templates, can I manage to get Post A's Title?

Because I don't want hardcoded Post A's title on Post A1,A2,A3's fields.

I'd tried this solution, but seems can't retrieve parent A's post object...

Below is my custom field settings on Post A's category, to select children products relationship ( which is A1,A2,A3 that mentioned above ) :

enter image description here

Thankyou

2
  • How is the relationship stored? Does ACF insert meta against Post A1, A2, A3 that says the parent post is "Post A" or?
    – Adam
    Feb 22, 2016 at 5:16
  • @userabuser I setup a relationship custom field on Post A. Then when i on Post A, I able to stored A1,A2,A3's post. The relationship fields seems doesn't have any settings for me to define parent / children post meta? I edited my question and posted a ss.... thanks!
    – Mavichow
    Feb 22, 2016 at 5:24

2 Answers 2

1

Since ACF Relationships doesn't set any relationship as a parent or child,you'd be better of just getting the title from your post.

You could simply get the ID of your A page: the_title( '43' ); and output it like this, or if the post is actually a parent, you could simply do the_title( wp_get_post_parent_id() ); on your child template.

0

This appears to be the case covered in the ACF documentation's Doctors and Locations example.

  • The relationship is stored on the Post A, as a list of post IDs for A1, A2, A3, and not the other way around.
  • To find A from A1, you'll need to query all posts for a meta value of the relationship that has value A1's post ID
  • But these are stored as a PHP serialised array. The article suggests a LIKE query for "123" where 123 is A1's post ID.

This is pretty horrible IMO but may be the only way without e.g. automatically reflecting the relationship into A1/2/3's post meta somewhere on save. And conceivably there could be a second post B that also has the same relationship to A1, so there's no guarantee you'll only get one result from the reverse search. (However assuming the relationship is stored as a serialised array of numbers only the query should be accurate at least: I can't see any other way for a quoted integer to exist in that string.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.