-1

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

2 Answers 2

0
    $book_args = array(
    'post_type'        => 'book',
    'posts_per_page'   => -1,
    'meta_key'         => 'name_ebook',
    'meta_value'       => 'Paintree'
);
0

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',
);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.