Help with wordpress loop to generate json api

Asked

Viewed 146 times

0

Hello good morning I would like a noose here in this code:

'Object'=> get_the_nome da imagem que esta no destaque()

'Categoria' =>get_the_nome da categoria

follows the complete code :

$args = array( 'post_status' => 'publish');

$loop = new WP_Query( $args );

$array = array();

while ( $loop->have_posts() ) : $loop->the_post();

    global $data;
    $array[] = array(

        'Object'=> 'aqui apenas o nome da imagem destacada',
        'Titulo' => get_the_title(),
        'Descricao' => get_the_content(),
        'Categoria' => 'aqui o nome da categoria',
    );

endwhile;

wp_reset_query();
ob_clean();
echo json_encode($array);
exit();
  • You should explain the question better. Besides, would you have someone do the code for you? This is a website about technical questions, not for people to solve their problem. In other words, you have to show some effort in solving the problem.

  • The boy everyone puts their codes here and doubts and that’s what I’m doing most I’ve already solved hug there for you too ! for those who have the doubt also follow the code that solved: $filename = basename ( get_attached_file( get_post_thumbnail_id() ) )

  • Code is correct. Ask for help as well. But you need to show some effort. Anyway wordpress.org is a good place to get help on the WP API.

  • 1

    Since you already found the answer. You can answer your own question and help other people ;)

1 answer

4


For the name of the highlighted image to do various things, even catch the title or the alt hers.

For title:

get_the_title( get_post_thumbnail_id() )

For the attribute alt:

get_post_meta( get_post_thumbnail_id(), '_wp_attachment_image_alt', true )

Already the category is simple to recover using get_the_category(), however it is important to note that this function returns an array, as each post can have infinite categories.

  • Thanks Cláudio Sanches solved the issue !

  • 1

    @You can mark the answer as accepted as well...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.