Home › Forums › Backend Issues (wp-admin) › Relationship field and subpages
Hi, I have a little problem.
I’ve created a relationship between articles e pages. Is there a way to show only the children of a parent page?
I’ve tried this solution:
add_filter('acf/fields/relationship/query/name=autore', 'my_function_name', 10, 3);
function my_function_name($args, $field, $post)
{
$args['post_parent'] = 47;
return $args;
}
The problem is that when the article page loads for the first time, i don’t get the list of sub pages, but if i do a research the results are right.
Anyone could help me?
Trying to do the same thing, showing only child pages of a parent in a relationship field. Other query args I tried work fine, but setting post_parent
shows only a “(no title) ()” in the list, though the child pages do show when I use the search field.
Also, several of these errors logged each time the page with the field loads:
PHP Notice: Trying to get property of non-object in /Users/.../wp-content/plugins/advanced-custom-fields-pro/api/api-helpers.php on line 1709
Seems like a bug.
Just want to add that I’ve been looking for a way to do this for a long time myself. Would be great if something for this was implemented.
Huzzah!
Appears ACF Pro version 5.1.6 fixed this issue. At least in my use case.
Cheers developer.
Weasel, I don’t see anything in 5.16 that does this. What am I missing? Seems to work exactly as it use to.
The part that works for me from the release notes is:
Core: Fixed bug when adding ‘post_parent’ value to post_object/relationship query args
It’s not a front-end admin feature. You need to use a filter in your functions to alter the query:
http://www.advancedcustomfields.com/resources/acf-fields-relationship-query/
Ah makes sense. Sorry, was assuming it was added to the admin interface to do it. Great to know it can now be done through a filter though!
I trie to make multiple pages childs in a relation field… but I’m getting (no title) () as a result in de acf relation field.
function my_relationship_query($args,$field,$post)
{
// This works fine to get the childs of one page with id 225
// $args[‘post_parent’] = 225;
// I’ve tried to get childs of multiple pages 225 and 83263 this doesn’t work (no title) ()
// $args = array(‘post_type’ => ‘page’, ‘post_parent’ => array(225));
// $args = array(‘post_type’ => ‘page’, ‘post_parent__in’ => array(225, 83263));
return $args;
}
Is this a bug?
since the problem with post_parent was a bug there is a chance that post_parent__in has a similar problem. Can you turn on error reporting on your site and post back any error messages that you get?
The topic ‘Relationship field and subpages’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.