Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
761
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?php
  2. /*
  3.     Template Name: Page No Title
  4. */
  5.  
  6. header('Content-Type: application/json');
  7. header("Access-Control-Allow-Origin: *");
  8.  
  9. $actual_link = "$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  10. // args
  11. $args = array(
  12.     'numberposts'   => -1,
  13.     'post_type'     => 'movie',
  14.     'meta_key'      => 'imdb_id',
  15.     'meta_value'    => preg_replace('/[^0-9]/', '', $actual_link)
  16. );
  17. // query
  18. $the_query = new WP_Query( $args );
  19. ?>
  20.  
  21. <?php if( $the_query->have_posts() ):     $json = array();?>
  22.     <?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
  23.     <?php
  24.         $bus = array(
  25.             'audio' => get_field('audio'),
  26.             'quality' => get_field('quality'),
  27.             'url' => get_field('url')
  28.         );
  29.         array_push($json, $bus);
  30.     ?>
  31.     <?php endwhile; ?>
  32. <?php endif; ?>
  33.  
  34. <?php
  35.     $jsonstring = json_encode($json);
  36.     echo $jsonstring;
  37. ?>
  38.  
  39. <?php wp_reset_query(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement