I'm trying to output the values of two custom fields created by ACF plugin in a custom post type. I actually need this to be displayed in a popup window. wordpress popup plugins don't support php code, only shortcodes can be called from the content editor. So I'm trying to create a shortcode to be used in the editor of the popup to display the values of the custom fields.
I know that we can generate shortcode [cite]
using this code in theme functions.php
function cite_shortcode() {
}
add_shortcode( 'cite', 'cite_shortcode' );
But i couldn't figure out how to add the php code to that code. I tried to do something like:
function cite_shortcode() {
<div>
<?php
$object_terms = wp_get_object_terms( $post->ID, 'issue', array( 'fields' => 'all' ) );
if ( $object_terms ) {
$res = '';
foreach ( $object_terms as $term ) {
if ( $term->parent ) {
$res .= $term->name . ', ';
}
}
echo rtrim($res,' ,');
}
?>), pp: <?php the_field('first_page'); ?>-<?php the_field('last_page'); ?>
</div>
}
add_shortcode( 'cite', 'cite_shortcode' );
But it didn't work. it shows:
Parse error: syntax error, unexpected
So, my questions are:
- how can i make that code work?
- is it possible to put the php code in cite.php file and output its values via a shortcode generated in functions.php? and how to do that?
Best regards