Home › Forums › General Issues › Retrieve ID instead of link from 'page_link' field-type › Reply To: Retrieve ID instead of link from 'page_link' field-type
Hi John,
Thanks, this does work.
However, unfortunately it doesn’t really solve my problem. I will elaborate a bit why.
We usually build sites where a global variable ($post_sets) is being assigned with all ACF metadata from a post, on single pages and in ‘the loop’. This is done with the function below function.
function get_post_options($post_id = null) {
if (function_exists('get_fields')) :
global $post_sets, $post;
$post_sets = '';
if (!is_numeric($post_id) && exists($post)):
$post_id = $post->ID;
endif;
<strong>$post_sets = get_fields($post_id);</strong>
// if $post_sets is 'false', we're assigning an empty array to it
// that's more handy for error handling.
if ($post_sets == false) {
$post_sets = array();
}
return $post_sets;
endif;
}
add_action( 'wp', 'get_post_options');
add_action( 'the_post', 'get_post_options');
If I would add false
to the $post_sets = get_fields($post_id);
line, I will lose all (very useful) formatting that’s being done by ACF. I even lose the field names of subfields.
I really only need to get rid of the formatting that’s being done by the page_link field. Am I wrong that various fields have a way of altering the formatting with a filter? Shouldn’t the page_link field offer such a thing as well?
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.