REST API: Display Category names in JSON?

For my needs, I customized the wp rest posts callback: function get_all_posts( $data, $post, $context ) { return [ ‘id’ => $data->data[‘id’], ‘date’ => $data->data[‘date’], ‘date_gmt’ => $data->data[‘date_gmt’], ‘modified’ => $data->data[‘modified’], ‘title’ => $data->data[‘title’][‘rendered’], ‘content’ => $data->data[‘content’][‘rendered’], ‘excerpt’ => $data->data[‘excerpt’][‘rendered’], ‘category’ => get_the_category_by_ID( $data->data[‘categories’][0] ), ‘link’ => $data->data[‘link’], ]; } add_filter( ‘rest_prepare_post’, ‘get_all_posts’, 10, 3 … Read more

Using Javascript for Looped Content

This may help <?php $staff = new WP_Query(array( ‘posts_per_page’ => -1, ‘post_type’ => ‘staff_bios’, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’ )); while($staff->have_posts()){ $staff->the_post(); ?> //Below is what should display for each post. <div class=”staff-thumb” onclick=”staffDetails(<?php the_ID(); ?>)”> //Thumbnail details here </div> //Below is the pop up container (hidden until called). <div id=”<?php the_ID()?>” class=”popup-wrap”> <div … Read more

Accessing WPDB Multidimensional JSON Array w/ Javascript

Looks like you want to use something like result = $.parseJSON(data). Then you can access the data with result.win_id, for example. As an aside, you should sanitize the input to that database query using prepare with something like: $wpdb->get_results( $wpdb->prepare( “SELECT * FROM wp_winners WHERE user_id=%d”, $user_id ) );

Javascript stopped working [closed]

One of your scripts doesn’t use jQuery correctly: $(document).ready(function () {} This cannot work because jQuery runs in no conflict mode in WordPress. To make it work change the script to: jQuery(document).ready(function ($) {}