Cannot access class properties from ajax call in wpordrpess

The problem was caused by another method inside the class: public function create_cart_id() { if( is_user_logged_in() ) { $this->create_logged_in_cart_id(); }else { $this->create_non_logged_in_cart_id(); } return $this->cart_id; – adding that line solved the problem } This method generates the $cart_id, but it didn’t return its value, so it was not accessible from outside and returned null.

Display post thumbnail after clicking on post id with AJAX

You can start by trying this. 1. Change this <span class=”id_53″>Display Post Image</span> to <span class=”id_53″ data-id=”53″>Display Post Image</span> 2. Create you js file $(function () { // click event example $(‘.id_53’).on(‘click’, getThumb); // call the ajax function getThumb() { $.post( ‘http://path/wp-content/themes/your-theme/ajax-file.php’ , ‘my_id=’+$(this).attr(‘data-id’) , showThumb ); } // get image source function showThumb(e) { … Read more

How do I display posts of a specific day?

First things first. Do not you query_posts(). Use WP_Query instead, to prevent messing with the main query. Now, as for your question. WP_Query allows you to enter data parameters too. It even has a date query which you can check it out in the link I’ve provided. Instead of using Admin-AJAX, you can write a … Read more

Class called in template, AJAX not registering

You can’t hook into AJAX in a template, because the template’s not going to be loaded by admin-ajax.php when the request is made. You need to hook into AJAX when the plugin is loaded. Since your hooks are defined in the class constructor (whether nor not this is a good idea is another issue), you … Read more