Tag Info

Hot answers tagged

6

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 url to be used ...


4

There has been quite a bit of development around the JSON REST API that is supposed to be merged into the 4.1 release. I believe it's officially going to be called the 'WP API'. You can begin using the codebase now and keep up with the latest developments here until it gets to core. Ryan McCue and team have fleshed out some pretty good documentation here.


3

While historically WP has been backā€“end centric, there had been declaration made for years now about moving towards heavy JS use. With backwards compatibility commitments in mind it is questionable that JS will achieve parity or take over PHP any time soon (in my opinion), but there had been some progress on it. The WordPress admin now ships with Backbone ...


2

To answer your statement: [...] there is no built-in Javascript API for Wordpress. Therefore developers who want to build on Ajax seem to come up all with their own solution which doesn't seem right to me. There is no "own solution" to be done. You can ease things by using ATP with ajax_template_part() by @G.M. or similar plugins and take a short cut, ...


2

Your main issue with your code is that you aren't wrapping your JS in a <script> element. <?php /* Template Name: Price Chart */ /** * Enqueue the table sorter script */ function load_table_sorter_scripts() { //wp_enqueue_style( 'style-name', get_stylesheet_uri() ); wp_enqueue_script( 'tablesorter', get_template_directory_uri() . ...


2

There is Woocommerce conditional tag for single product page Try if(is_product()) instead of if ( is_page_template( 'single-product.php' ))


1

From comment: There is not enough information to answer your question. All your code is javascript, not PHP. Additionally, there is no function named "setCookie" or "getCookie" in javascript, and you don't state what libraries you are using. The answer is most likely that your setCookie function is using the current page path (cookies have a URL path ...


1

Have much to say about both W3TC and pagespeed, but will try to stay on the point. You should never have a JS external element in you HTML as part of the actual content, they should be either in the head element (but only scripts that must be loaded before the page finishes loading) or just before the end of the body. CSS should be only in the head ...


1

Almost there with your PHP function. No need to set the header. (Edit: Also, assuming get_posts() is actually returning results.) function myAjaxFunc() { $posts = get_posts( array( 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'post_type' => 'my-post-type', ...


1

@BODA82 answer helped, but eventually I realized that I should have replaced responseText with responseJSON method in my javascript code. In the example below I was storing the ajax response results in a variable. I didn't know there was a specific method to get response in JSON. In such way the object/array with get_posts() results is returned correctly and ...



Only top voted, non community-wiki answers of a minimum length are eligible