wp_ajax_[service] returning 0
According to the WordPress documentation, you should call die() at the end of your PHP function to return proper results.
According to the WordPress documentation, you should call die() at the end of your PHP function to return proper results.
$comments, or $wp_query->comments, is initialized by comments_template(), which you call in your template file when you want to load the comment sub-template file. So at the time of template_redirect it is not yet initialized. As Chris said, you should call get_comments() and pass it the post_id of your current post. If you’re doing AJAX calls, … Read more
What you are looking for is AJAX navigation. It’s not that complicated, however it’s not very easy too. I’ve written a simple example for you, I hope it helps you in your case. An AJAX request has 2 steps, first a front-end request that is sent out by browser when for example a user clicks … Read more
Ok, you want that mobile devices always load mobile templates. Desktop devices load template files based on resolution: if < 1080 mobile ones, > 1080 desktop ones. Your workflow should be: On init you check for mobile devices using wp_is_mobile. If true you add a template filter that returns str_replace(‘.php’, ‘-mobile.php’, $template); where $template is … Read more
You will need to create a WordPress function that loads the post content and hook that into wp_ajax_nopriv. You will also need the jQuery ajax functions to send the $_POST data to your WordPress function via ajax and output the returned content in your empty div where you want it to display. A simple approach … Read more
You can technically make a XHR to post.php via JavaScript. Below is a proof-of-concept for saving/editing posts only. I haven’t tested it at all, so I’m sure you will need to tweak it. I wanted to give you a basic workflow for accomplishing something like this. You can take it and run with it if … Read more
Try changing your script to this since you’re not actually running a cross-browser request: <script> (function($) { $(document).ready(function() { var refreshId = setInterval(function() { $(‘#content’).fadeOut(“fast”).load(‘/new.php’).fadeIn(“fast”); $(“#content .span9 article”).unwrap(); }, 10000); }); })(jQuery); UPDATE: Wrapped in WP-friendly jQuery no-conflict code…
Thanks Muhammad, Your solution is a fantastic working framework on which to base real world AJAX calls. I just added this code to the plugin main php file for a shortcode so I could use it in the Front End too. //For front end use in production add_shortcode(‘wp_testingPlugin_shortcode’, ‘wp_testingPlugin_shortcode’); function wp_testingPlugin_shortcode() { wp_enqueue_script( ‘ajax-script’, plugin_dir_url( … Read more
You will have to make a second button for down voting. Give the upvote button a class of up and the down vote button a class of down. jQuery <?php wp_enqueue_script( ‘jquery’ ) ?> <?php wp_head(); ?> <script type=”text/javascript”> jQuery(document).ready(function() { jQuery(“.vote a.up”).click( function() { var some = jQuery(this); var thepost = jQuery(this).attr(“post”); var theuser … Read more
I was in the same situation as you recently. The way I did it is probably wrong, and prone to bugs but if you can live with that then this might help. Basically you create an empty array at the top of your loop file, say for example loop-index.php. $ignores = array(); Then inside your … Read more