Home › Forums › Feature Requests › relationshipfield with direct link to post
I like the relation field and i have a lot of posts in it. but it would be cool to have a direct link button next to the “minus” button. then i can go to that post which is selected on the right side. now i have search it in my posts overview.
Hi @nicmare,
Have you tried using the acf/fields/relationship/result
filter to add the link to the post on the text that displays for each post.
The code is simple, it should be as follows:
add_filter('acf/fields/relationship/result', 'my_relationship_result', 10, 4);
function my_relationship_result( $result, $object, $field, $post ) {
$link = '<a href="'.get_permalink($object->ID).'"">Link text</a>';
$result = $result . ' ' . $link;
return $result;
}
Have a look at acf/fields/relationship/query for more information.
great! acf for ever <3 !
But this generates a frontend link. i need a link to the edit page of each item in the relationship field.
OR is there a better way to do this than this:
$link = '<a href="post.php?post='.$object->ID.'&action=edit">[edit]</a>';
Hi @nicmare,
Hmm… another way would be using get_edit_post_link(...)
WP method. The code should be as follows:
$link = get_edit_post_link($object->ID);
For more information, have a look at:
http://codex.wordpress.org/Template_Tags/get_edit_post_link
and how can i exclude results? i tried this:
function only_big_images( $html, $post ) {
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'shop_catalog' );
if($image[1] >= 600){
return $html;
}
}
but then in the relationship field list still exist “empty” items with the label “null”. i want to hide them completely from the list!
The topic ‘relationshipfield with direct link to post’ 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.