Hello. I’m hoping someone can help me figure out a way to handle this.
I have two core post types on a development project I am working. A post type for the sales staff and a post type for the locations (which have a bi-directional relationship with the sales staff to display the staff at a particular location). These post types have very specific field groups utilized for pages within that type.
The above is already built.
I am trying to get those post types hierarchical, but accessed through another new post type with options for a parent post for both all the sales posts as well as all the location posts, to utilize the page path used for those post types. I need it to be a separate post type because they need unique post fields that the “parent” post within locations and sales should not include.
For example:
domain/sales/sales_person_name/page_specific_to_this_person
domain/location/name_of_location/an_event_happening_at_this_location
I want to create an entirely other post type for child pages of both of these. With attributes available, select from all posts from both the sales staff post type as well as the location post type. Alternatively, if that is not possible, can I change the permalink manually to initially post from the root, but also access perhaps the relationship structure of the permalink to a sales or location?
Is this something achievable?
Hi! For a client of mine, I am trying to implement a Related Posts functionality using ACF. With the Relationship field, the client can select which posts are related to the post they’re editing, and by using the bidirectionality setting, said related posts link back to the initial post. However, for proper related posts functionality, it would of course make sense if all related posts would then automatically be linked to all other related posts within the same scope.
For example, if I edit the post with ID 1, and select posts 2, 3, and 4 as related posts, post 2 automatically has post 1 as a related post. However, it should also be linked to posts 3 and 4, without needing to edit post 2 manually.
Is this something that can be achieved with ACF? Does my question even maken sense? ๐
Thanks in advance!
I submitted a ticket to what now seems to be WP Engine support to no avail, so will post here just in case!
I have a block called Link List, which well is just a list of links. It was a repeater for manually entered link items but it was updated to include existing site content as well. I seem to have successfully migrated the fields in the old repeater to the fields in the updated repeater, I can see them in block preview and when viewing the block on the front end. However, when editing the block, there are no populated fields to edit.
Old json – repeater field with three subfields (subhead, url, short_description):
{
"key": "field_64837282e5ad9",
"label": "Old Link List Items",
"name": "items",
"aria-label": "",
"type": "repeater",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"layout": "block",
"pagination": 0,
"min": 0,
"max": 0,
"button_label": "Add Row",
"rows_per_page": 20,
"sub_fields": [
{
"key": "field_6483729ae5ada",
"label": "Old Subhead",
"name": "subhead",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": "",
"parent_repeater": "field_64837282e5ad9"
},
{
"key": "field_64837357e5adc",
"label": "Old URL",
"name": "url",
"aria-label": "",
"type": "url",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"parent_repeater": "field_64837282e5ad9"
},
{
"key": "field_648372afe5adb",
"label": "Old Short Description",
"name": "short_description",
"aria-label": "",
"type": "textarea",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": 155,
"rows": "",
"placeholder": "",
"new_lines": "",
"parent_repeater": "field_64837282e5ad9"
}
]
},
New json – repeater with three sub fields (entry_method, custom_item, existing_item), the custom_item containing the original three item fields (subhead, url, short_description) from above.
{
"key": "field_66b4df4663782",
"label": "Link List Items",
"name": "link_list_items",
"aria-label": "",
"type": "repeater",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"layout": "row",
"pagination": 0,
"min": 0,
"max": 0,
"collapsed": "",
"button_label": "Add Link Item",
"rows_per_page": 20,
"sub_fields": [
{
"key": "field_66b11540e682f",
"label": "Entry Method",
"name": "entry_method",
"aria-label": "",
"type": "select",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {
"custom": "Custom URL",
"existing": "Existing Page Content"
},
"default_value": "custom",
"return_format": "value",
"multiple": 0,
"allow_null": 0,
"ui": 0,
"ajax": 0,
"placeholder": "",
"parent_repeater": "field_66b4df4663782"
},
{
"key": "field_6758a9a91df40",
"label": "Custom Link List Item",
"name": "custom_item",
"aria-label": "",
"type": "group",
"instructions": "",
"required": 0,
"conditional_logic": [
[
{
"field": "field_66b11540e682f",
"operator": "==",
"value": "custom"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"layout": "block",
"sub_fields": [
{
"key": "field_6758a8101df3e",
"label": "Subhead",
"name": "subhead",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
},
{
"key": "field_66b4e13bd37ad",
"label": "URL",
"name": "url",
"aria-label": "",
"type": "url",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": ""
},
{
"key": "field_66b4e13bd37ae",
"label": "Short Description",
"name": "short_description",
"aria-label": "",
"type": "textarea",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": 155,
"rows": "",
"placeholder": "",
"new_lines": ""
}
],
"parent_repeater": "field_66b4df4663782"
},
{
"key": "field_66b1161ae6830",
"label": "Existing Link List Item",
"name": "existing_item",
"aria-label": "",
"type": "relationship",
"instructions": "",
"required": 0,
"conditional_logic": [
[
{
"field": "field_66b11540e682f",
"operator": "==",
"value": "existing"
}
]
],
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"post_type": "",
"post_status": "",
"taxonomy": "",
"filters": [
"search",
"post_type",
"taxonomy"
],
"return_format": "id",
"min": "",
"max": 1,
"elements": "",
"bidirectional": 0,
"bidirectional_target": [],
"parent_repeater": "field_66b4df4663782"
}
]
}
PHP – migrating the old item fields into new Link List Items > Custom Item
$old_items = get_field('items') ?: [];
$link_list_items = get_field('link_list_items', $post_id) ?: [];
if ($old_items) {
foreach ($old_items as $old_item) {
$is_duplicate = false;
foreach ($link_list_items as $existing_item) {
if (
$existing_item['entry_method'] === 'custom' &&
$existing_item['custom_item']['subhead'] === $old_item['subhead'] &&
$existing_item['custom_item']['url'] === $old_item['url'] &&
$existing_item['custom_item']['short_description'] === $old_item['short_description']
) {
echo '<p>Duplicate found:</p>
'; var_dump($old_item); echo '
';
$is_duplicate = true;
break;
}
}
// If not a duplicate, add to the new structure
if (!$is_duplicate) {
echo '<p>Adding new item:</p>
'; var_dump($old_item); echo '
';
$link_list_items[] = [
'entry_method' => 'custom',
'custom_item' => [
'subhead' => $old_item['subhead'],
'url' => $old_item['url'],
'short_description' => $old_item['short_description'],
],
'existing_item' => null,
];
}
}
echo '<p>New link_list_items array to update:</p>
'; var_dump($link_list_items); echo '
';
// Update the field with the current + migrated items
$update_result = update_field('link_list_items', $link_list_items, $post_id);
// // Check if the update was successful
if ($update_result) {
echo '<p>Field updated successfully.</p>';
} else {
echo '<p>Failed to update field.</p>';
}
}
Just to reiterate, after running the migration script I can now see the old field data in the new fields on the front end, but if I edit the Link List block it’s as if there is no content.
Any help troubleshooting this would be appreciated, thanks!
I have two custom post types, Locations and Event. Both have a ACF Bi-Directional relationship field.
I have created a true/false field for locations.
Now I want to show only events from the locations that have true field.
how can I do that?
Hi! I would like to use bidirectional taxonomies for related posts, with the minor complication that one post type should should absorb the terms from multiple related posts (of another post type).
Here’s my use case: On a portfolio website I have a post type called “Projects” and one called “deliverables”. Projects will have (often multiple) deliverables related with them using the ACF relationship field.
Deliverables have a taxonomy called “features”. I have also added this taxonomy to Projects. On the front-end I would love to be able to filter Projects based it’s related Deliverables’ features. So that means the Projects’ Features taxonomy will need to have a bidirectional relationship with multiple related Deliverables.
How can I achieve this? Thoughts? Thanks!
Hi, my goal is to redirect a non admin user to a specific page after the login, where the url is a CPT url which acts as its private area of investors.
I have a CPT called “investors”, and a bidirectional ACF user field which relates each post with user/s allowed to see it.
Which is the best approach to achieve this?
If a post is related to two users, I should redirect these users to the exact post after their log in.
Thanks in advance
Hello! I run a concert website. We have a post type for artists , recent press and concerts, which are bidirectionally related with an ACF relationship field. In the press admin, I would love to be able to filter posts by artist. Currently, if I click the artist name, it links to the associated artist page, which is fine. But then there is no way to filter posts. Any help would me much appreciated ๐
Hello,
I am using Advanced Custom Fields PRO Version 6.2.7
Recently I have noticed that when I want to update a relationship field with multiple values, the whole ARRAY is not saved, but only the first value of the ARRAY.
I have used this code as a test:
update_field('menu', array(123,456), $post_id);
This is the output with var_dump:
int(123)
These are my settings for the relationship field:
{
"key": "field_60c789afded44",
"label": "menu",
"name": "menu",
"aria-label": "",
"type": "relationship",
"instructions": "",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"wpml_cf_preferences": 1,
"post_type": [
"product"
],
"taxonomy": [
"product_cat:new"
],
"filters": [
"search",
"taxonomy"
],
"elements": "",
"min": "",
"max": "",
"return_format": "id",
"bidirectional_target": []
},
Hi,
I found a bug in the relationship between a custom taxonomy and the users.
I have a custom taxonomy ‘genres’ with an assigned field group with a field for assigned users.
Name: ‘rel_users’
Field Type: User
Select Multiple: True
Bidirectional Target Field: rel_genres
A second field group is assigned to ‘users’ and has a field for assigned taxonomy.
Name: ‘rel_genres’
Field Type: Taxonomy
Appearance: Multi Select
Bidirectional Target Field: rel_users
If I assign a user to a genre term, everything is ok.
term_id: 15
user_id: 5
wp_usermeta
meta_key: rel_genres
meta_value: a:1:{i:0;s:2:”15″;}
wp_termmeta
meta_key: rel_users
meta_value: a:1:{i:0;s:1: “5”;}
In the backend the relations are displayed correctly in the user profile and on the taxonomy edit page.
However, when I make changes on the taxonomy edit page, the target value is changed incorrectly (when I delete, save and reassign the user) so that the assignment in the user profile disappears. When saving the taxonomy term, the bidirectional target field is now saved as an interger array instead of string array.
wp_usermeta
meta_key: rel_genres
meta_value: a:1:{i:0;i:15;} <- integer array!
wp_termmeta (unchanged)
meta_key: rel_users
meta_value: a:1:{i:0;s:1: “5”;}
It seems that the array with integer values destroys the relationship on the side of the user.
best regards
steffen
Hi,
i use ACF in combination with breakdance and the breakdance post loop builder.
I want to query the players of a team by their position. Goalkeepers, Defenders, …
For the players and the teams i use a Bidirectional relationship.
It takes about 10 seconds to load the page.
Has someone an idea why it takes so long?
return
array(
'post_type' => 'spieler',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'sp_position',
'value' => 'Tor',
'compare' => '='
),
array(
'key' => 'team_spieler',
'value' => '"' . get_the_ID() . '"',
'compare' => 'LIKE',
),
),
'orderby'=>'meta_value',
'meta_key' => 'sp_nachname',
'order'=>'ASC',
);
Screenshot Loop:
Screenshot ACF Player:
Hello,
I am building a wordpress webiste with Avada (ThemeFusion Bulider). With ACF I have created two CPT: (learning) Pilars and Courses.
The CPTs have relationship fields (bi-directional relatinoship).
a) So far, when at the frontend I’m navigating to a specific Pilar post I’ve managed to display the related Courses. This is working fine.
What I want to do now is when I navigate to a specific Course post:
b) to display (a link to) the Pilar it belongs to. I’ve managed this!
c) to display (links to) Courses that belong to the same Pilar as this specific Course.
How can I do this?
Many thanks
Giorgos Nikolaidis
Larissa, Greece
Hello,
I went through some documentation such as this one https://www.advancedcustomfields.com/resources/bidirectional-relationships since I am not too good in coding, I am not sure if this is what I need to achieve what I am trying to setup on my website and need some guidelines to reach my objectives.
I have 2 post types:
1. Bid Requests
2. Bid Proposals
I created a bidrectional relationship between each of these post types:
bid_request_related_bid_proposal – This field is a relationship field but hidden and is to link a bid proposals to the bid request.
bid_proposal_related_bid_request – This field is a relationship field but hidden and is to link a bid request to bid proposals.
Now let me try to better explain what I am trying to achieve.
A user will submit a bid request with his requirements etc. On this same bid request post single page, I will add a form for other users to submit bid proposals for the current bid request post.
Meaning that, each submitted bid proposal will be a custom post and such custom post should automatically be added as relationship to the current bid request post (post ID).
I don’t want users to need to search/select the bid request when submitting their bid proposals but the bid proposal to be automatically connected as a relationship posts through the relationship fields mentioned above.
Hope that make sense!
I’m doing a real estate website. I have CPT for Properties and one for Staff. I have a name field that connects a single property to a single staff member (an agent), and also the staff member can have multiple properties connected through the name field. This is all working as expected. What I need to do now is add a field to the staff member record called Assistant, that will be linked to another staff member who is that person’s assistant. Since the name field is already related to the properties record, how can I connect the name to the assistant field also?
What is the right way to go about this without messing up my properties – staff bi-directional relationship? (I have the ACF Post-2-Post plugin installed.)
Here are my field groups:
Staff: https://app.screencast.com/j7QTSKqVeBQYL
Properties: https://app.screencast.com/ERNyftLSeZjI5
Hey All,
Issue persists on ACF Bi Directional Fields in Bricks. I’m having trouble Querying Field from Post Type B to show up on Post Type A.
Type A = Books.
Type B = Authors.
I cannot get Author Field: “author_age” to appear on Book Post. Any ideas how to fix this? I’ve implemented ACF Bi Dir Code. Any help is appreciated!
php code from ACF – (https://www.advancedcustomfields.com/resources/relationship/)
hello
i have many custom post type
1- people
2- events
3- locations
and i use repeater field on events like this
ROW contain :
– User (post object from people post type)
– location ( repeater ((nested))
— location (post object from locations post type)
— user nickname (text)
– status (text)
i try to use (Bidirectional) plugin from ACF extend with this code (https://alf-drollinger.com/bidirectional-relationships-in-acf/)
to connect the locations and events with the people single page , it work fine BUT when i edit the people single page for any single page the field delete the content .
is there any way to solve this issue or other way to make it work , i want to show on single-people.php the events and locations that the user was on it
Here is my current set up:
3 CPT
4 ACF fields
When I create/edit a Solutions page, I am able to select all the services available within that solution. Same for Services page, I am able to select all the related Solutions it falls under. This was originally put together by another developer that probably didn’t know about bidirectional relationship so I left it as is.
On the companies page, there is a relationship field to Services & Solutions CPT. So as the editor, I would once again have to select the Solution and the individual services for each company as they will all differ.
Currently there is a major disconnect and a lot of double work as far as having to constantly select Solutions & Services.
I decided to edit the Solutions and Services CPT so that they use a bidirectional relationship field called “associated with”. So a Solutions can have multiple services, a service can be in multiple Solutions.
The part I am having a hard time on is somehow connecting that to the Company CPT.
I’d like to be able to select just the solutions that are available for each Company and have a list of the services associated with that solution be made available for edit. So for instance, a company might have Solution A which has 5 services available but they only offer 4. So they would need to be able to remove 1 w/o it affecting the original Solution & Services bidirectional relationship.
Is that possible? I’m not sure how to go about doing this.
Hello, I have a custom field called ‘linked_requests’ that’s stored in wp_postmeta. The value stored in this field is a serialized array (format -> a:1:{i:0;s:3:”123″;i:1;s:3:”124″;}). The existing values were made using the function “bidirectional_acf_update_value” described in:
https://www.advancedcustomfields.com/resources/bidirectional-relationships/
I want to make an automatic matching system, instead of the one above that requires field values to be manually selected when editing a post.
So now I’m trying to loop through wp_postmeta and see if a post id in this table and the current user’s post id contain 4 fields with the same value. If they have matching values, then a serialized array should be made in field ‘linked_requests’ containing the current user’s post id. The serialized array should be able to contain multiple post id’s (like the example used above).
But, if the ‘linked_requests’ field already contains a serialized array but does not contain the current user’s post id, then I would like to add the current’s user’s post id to the existing serialized array. How would I go about reading and updating this array?
I’m working on creating bidirectional term relationship fields. There’s a taxonomy multi-select field called related_terms, and when a term is saved with some relationships selected, I want to update those terms’ related_terms fields to include the saved term’s ID. I’m using update_term_meta() to save the related_terms array.
I have the related term ID array saving correctly to the database; it’s serialized just like terms selected through the interface. But when I refresh the edit term screen for the related term, Select2 isn’t recognizing the selected options. They’re selected correctly in the hidden field, and I can see them flash by in the form before Select2 loads, but then the field appears empty.
Have I missed something involving caching, or do I need to reinitialize Select2…?
Hello everyone !
I’m building an online course system using ACF and I want to create a “to do checklist” functionality to every lesson.
Context :
Every lesson is a CPT named โlessonโ.
I’m having a repeater field assigned on every lesson CPT allowing the admin to add steps that the user have to follow.
I’m able to display every row of the repeater dynamically on the front-end with Divi and Divi Engine plugins.
My need :
I want to add the ability for the user to check the steps when they are done. So I want to have a checkbox that the user car check or uncheck on the frontend.
But the problem is that the saved checkbox value need to be specific to 3 levels of information simultaneously : the lesson, the step (repeater row) and the user.
So in the DB I need to have a table that store for every user the checkbox value for every step defined in each lesson CPT.
When I add a new lesson with specific steps (repeater rows) I need to be able to edit the value of the checkbox for every users.
Then I also need to make that work fast (maybe with JSON) because I don’t want to lookup in a huge user list for every single step value. Need to structure data efficiently.
Some of the methods I’ve tried that didn’t worked :
I tried to build a system to mirror the fields AND VALUES created in the lessons and make them appear on the user fields and make the checkbox only available on the user side. I tried to use “clone” fields, templates, relational fields, nested repeaters with relational fields, bidirectional relational fields but nothing worked and that created a big mess that I’ve cleaned up.
Maybe there is a way to have only a specific field on a group assigned to a post type to have a unique value for each user ? I’m lost lol
PS : I only have very very basic PHP skills, I can understand basic existing codes on a wordpress architecture and bring it little modification but I’m not able to code a plugin from scratch ๐
Futures enhancements if the first part is working :
– Add more type of steps like one asking the user to submit a text allowing the teacher to ask question to check if the lesson is well learned or a more complicated quizz system with a score calculation
– Filter the data as the courses programs will be structured like this : Program > Module > Lesson and i’m using woocommerce membership to restrict the content
– By default the data of the steps is displayed on each course lessons but it would be interesting to build a synthesis of the user avancement on a specific page so I would need to be able to print the data based on the user for this page, instead of the lesson.
Thanks in advance, guys !
Alright, Iโm still new to ACF so trying to understand bidirectional relationships and such.
Iโm going to use a simple example with super bare boned data but how would you structure this?
Hockey season
Player name
Hockey season would need to show years maybe all the players who played that year and how many total goals per year
Players would show basic info then seasons played and goals each season.
This is how I think, but correct me if Iโm wrong
CPT Seasons
ACF Season
โ year
– players (relationship list)
– goals each player (relationship)
CPT Players
ACF Player
โ Name
– Seasons (repeater)
โ- Season (relationship)
โ- goals (relationship)
And if Iโm correct, how would I go about showing a league leaders on the season page
Goals
Player – 45
Player2 – 34
Player3 – 24
I donโt really know how to call the player subfield from the seasons page. Suggestions?
(And if my structure is bad just let me know too)
Thanks
Hi,
I have a conceptual question. Think about the example books and authors. I made a webshop that sells books. BOOKS (WooCommerce products) have different attributes for description and filtering.
They also have a bidirectional relationship with AUTHORS. So there is also the CPT author, that also comes with some fields and images to describe them.
Now, I realize I could also create a custom taxonomy for the WooCommerce product (book). I was not aware that I can add custom fields to a custom taxonomy, i.e. it will server like a category but at the same time describe the category in more detail with custom fields.
I am asking myself now: would it be better to assign the custom taxonomy to the books, instead of creating a separate CPT author and bidirectional relationship?
(actually, it’s composers and musical pieces but easier to comprehend with books and authors)
best regards
Markus
Hi! Ive got a bidirectional relationship between two post types and i want to have post type A’s post featured image to auto populate an image field in post type B’ post where the two posts hase the bidirectional relationship. If you can how would you do that?
Thanks for your time! ๐
Hi there,
First of all: thank you for the amazing plugin and functionalities. I have a question:
https://www.advancedcustomfields.com/resources/bidirectional-relationships/
I was reading this and I loved the explanation, but I was wondering: how can I get multiple values efficiently?
1 – How does this snippet affect the performance / queries on the post pages?
2 – What is the best way to get multiple fields to be bidirectional? Example: I want a field called X and a field called Y to be bidirectional – can I use the same function in PHP or do I have to duplicate it in functions.php?
Hi all!
I need to create a bi-directional relationship with my posts. I have created a single relationship system and it works perfectly. I have two types of posts to get related created with Custom Post Type UI. I need to relate only each type with the same type. So field_type A –> A and B –> B.
I followed this guide https://www.advancedcustomfields.com/resources/bidirectional-relationships/, copied it in my functions.php and replaced the field_name in the add_filter parameter but it is not working. The problem is why am I using a different field_type?
I prefer using directly a function instead of using a plugin…
Many thanks for every help! Much appreciated! ^^
Hi,
I have managed to set up automatic bidirectional relationships between two posts. I am using ACF Extended Plugin for this, but later I’ve discovered John Huebner has successfully achieved this feature with his Post-2-Post plugin.
What I need to to is to distinctly record incoming and outgoing relationships.
Let me explain:
a) I have a court case X and another court case Y.
b) X case refers to Y.
Here I can relate these two cases, but it is not apparent which case refers to another. Only obvious thing is that these two cases are related.
I remember this question was asked a couple of years ago, but I couldn’t find the exact forum thread. Mr. Huebner was saying this is possible, by recording the incoming and outgoing relations in two different records in the database.
Are there any updates about the issue? How can I achieve this?
Thanks.