In custom post type book I have several books published I just want to show data obtained from metabox field but I have not been able to help me the code that I am showing does not work
<?php $book=get_post_meta( get_the_ID(), 'name_ebook', true ); ?> return name ebook Paintree
<?php
$loop_args = array(
'post_type' => 'book',
'order' => 'ASC',
'meta_key' => '$book',
'orderby' => 'meta_value',
); ?>
show only search Paintree ebook
In custom post type book I have several books published I just want to show data obtained from metabox field but I have not been able to help me the code that I am showing does not work
<?php $book=get_post_meta( get_the_ID(), 'name_ebook', true ); ?> return name ebook Paintree
<?php
$loop_args = array(
'post_type' => 'book',
'order' => 'ASC',
'meta_key' => '$book',
'orderby' => 'meta_value',
); ?>
show only search Paintree ebook
Share Improve this question asked Jun 4, 2020 at 23:26 StymarkStymark 372 bronze badges2 Answers
Reset to default 0 $book_args = array(
'post_type' => 'book',
'posts_per_page' => -1,
'meta_key' => 'name_ebook',
'meta_value' => 'Paintree'
);
You're not using $book
as a variable in your $loop_args
, but as a string $book. Just remove the quotes around the variable in the args and it should work (assuming get_post_meta returns something and not just empty string).
$book = get_post_meta( get_the_ID(), 'name_ebook', true );
$loop_args = array(
'post_type' => 'book',
'order' => 'ASC',
'meta_key' => $book, // no quotes needed here
'orderby' => 'meta_value',
);