Convert Custom Post Data to Javascript Array for Autocomplete

$args = array( ‘post_type’ => ‘promo’ ); $loop = new WP_Query( $args ); $promos = array(); while ( $loop->have_posts() ) : $loop->the_post(); foreach((get_the_category()) as $category); $promos[] = $category->cat_name. ‘ – ‘ .get_the_title(); endwhile; echo ‘<script> jQuery(document).ready(function($) { var promoList=”.json_encode($promos) .”; $( “#auto-promo” ).autocomplete({ source: promoList }); }); </script>’;

Creating custom URLs with template to fetch external JSON

Turns out it was just really Friday for me. Thanks to @eddiemoya and @matt-keys for their answers on this question. Their answer helped me a lot. After their explanation I revisited the WordPress documentation and it really wasn’t that hard to comprehend. The solution I user for my specific question was as follows: I created … Read more

Best way to make a JSON API from WordPress?

I dont know how to edit question, I found this: but this way I cannot specify my requests, is there any way to modify this code so that I can specify it? function check_api_data() { if(isset($_GET[‘api’]) ) { if ($_GET[‘api’] == ‘json’){ $args = array( ‘post_status’ => ‘publish’, ‘nopaging’ => true, ‘orderby’ => ‘title’, ‘order’ … Read more

How to create REST Based JSON API(how to modify the code below)?

try this: if (isset($_GET[‘api’])) { if ($_GET[‘api’] == ‘json’ && isset($_GET[‘id’])) { $args = array( ‘p’ => $_GET[‘id’], ‘post_type’ => ‘any’// ID of a page, post, or custom type ); $query = new WP_Query($args); // $query is the WP_Query Object $post = $query->post; // $post contains the post object header(“content-type: application/json”); echo json_encode($post); } exit(); … Read more

Why does “if statement” has to “die()”, otherwise wont work?

Most likely it’s simply because $_GET[‘first’] is not defined when you try with ?second=case&id=204. Instead, try this CODE (assuming first & second can’t appear at the same time): if (isset($_GET[‘api’])) { if (isset($_GET[‘first’]) && $_GET[‘first’] == ‘case’ && isset($_GET[‘id’])) { // $query is the WP_Query Object $post = get_post($_GET[‘id’]); // $post contains the post object … Read more

I can’t get those posts from the wordpress to ionic

The API endpoint for the post type ‘accomodation’ is /wp-json/wp/v2/posts?type=accomodation Custom Post Types however are not shown in the API by default. You can enable this per Post Type by adding show_in_rest’ => true, to the register_post_type arguments. Documentation can be found here