Hi,
I’ve tried looking at the documentation and not sure if I’m heading towards the right direction or what’s wrong with it.
Basically all I want is beneath the at to display the location that’s queried from ACF
Initially I used PageLink, but I found out that it only returns the permalink and not the title.
I’ve set up the following code in my functions.php
and while it does work, I’m not sure how to make it display in Pro, something like <a href="{{dc:acf:location_url}}">{{dc:acf:location_title}}</a>
This is the code in the functions.php
function display_acf_post_object_location() {
// Check if we are on the specific page
if ( is_page('apex-challenge-2') ) {
// Assuming 'location' is your ACF Post Object field name
$post_object = get_field('location');
if ( $post_object ) {
// Retrieve the post title
$post_title = esc_html( $post_object->post_title );
// Retrieve the post URL
$post_url = get_permalink( $post_object->ID );
// Display the title and URL
echo 'Location Name: ' . $post_title;
echo '<br>';
echo 'Location URL: <a href="' . esc_url( $post_url ) . '">' . $post_title . '</a>';
}
}
}
function custom_acf_content( $content ) {
if ( is_page('apex-challenge-2') ) {
ob_start();
display_acf_post_object_location();
$location_content = ob_get_clean();
return $location_content . $content;
}
return $content;
}
add_filter( 'the_content', 'custom_acf_content' );