Get Previous & Next posts by Post ID

Take a look at get_previous_post() and get_next_post() and you’ll see they both use the get_adjacent_post() to find the previous or next post. Let’s say you want to fetch the ID of the immediately previous post based on the current post’s ID. This is what you’d do: function get_previous_post_id( $post_id ) { // Get a global … Read more

Is there a JavaScript API? How to access public and private data in JS?

TL;DR There is no JavaScript API in the WordPress core and no one is planned, but actually, there is no need of it. Backend First of all let’s say that, regarding the backend, some useful information can be fetched from already present JavaScript global variables (WordPress loves all global flavors). E.g. ajaxurl for the admin-ajax.php … Read more

AJAX with loop filtering categories

I know this is old, this looks exactly what I need, but isn’t working ATM. I paste everything on functions.php for a reason. ONE: Category Loop for theme file: Printed it with a shortcode, because i’m using bakery I wan’t to put it in an specific place in the site. This is Working fine. <?php … Read more

Making my AJAX powered WordPress Crawlable

Specifically AVOID using “hashbang” (“!#”) in order to make AJAX powered WordPress sites crawlable. You really don’t want to use the “hashbang” method on a WordPress site. The “!#” is more like a hacky patch for sites that cannot provide a static analog to it’s AJAX version. Its use in general is not recommended by … Read more

Use AJAX in shortcode

First off, this is very borderline within the scope of WPSE, it at all. Apart from the shortcode to trigger the initial HTML output, this is really just AJAX. Anyhow, that being said, this is how it’s done: The PHP Assuming that the above PHP snippet you supplied is functional, place the following in a … Read more

WordPress AJAX with Axios

you can use FormData an example: let form_data = new FormData; form_data.append(‘action’, ‘myAction’); form_data.append(‘first_name’, ‘my first name’); form_data.append(‘phone’, ‘my phone’); axios.post(myVars.ajax_url, form_data).then(function(response){ console.log(response.data); })