Hello,
I have created a book review web application using WordPress, and I have created a custom post type ‘book’ along with custom fields such as ‘author’ using ACF plugin.
In my single-book.php template, I want to show books that belong to the same author at the bottom of the page.
My problem is, I don’t know how to assign the author field to the meta value. This is the code I’m using which works perfectly when I specify the author for example ‘Paula Hawkins’:
<?php
$posts = get_posts(array(
‘numberposts’ => -1,
‘post_type’ => ‘book’,
‘meta_key’ => ‘author’,
‘meta_value’ => ‘Paula Hawkins’,
‘post__not_in’ => array( $post->ID )
));
if( $posts ): ?>
<?php wp_reset_postdata(); ?>
<?php endif;
?>
instead of specifying the author, I want to get the author using code that will work for all pages using this template of course.
i tried saving the author in a varibale like this:
$author = the_field(‘author’);
and then changed the meta value field to this:
‘meta_value’ => $author,
but its not working.