ajax refresh to display new posts

Try this guide to write an ajax request for your homepage. It’s plenty self explanatory. Then, using jQuery, make request to the website every 30 seconds or so. There is no way to notify a client about a post being published, the client itself has to check whether there is a new post published or … Read more

WordPress Ajax Filter

In the way you are using wp_localize_script(), the object’s name is filters, not reports; so, in filter.js you should use filters.ajax_filter. Also, you should define the variable options before use it. $( document ).ready(function() { $(“input:checkbox”).on( “change”, function() { console.log($(‘input[name=”filter[]”]:checked’).serialize()); jQuery.ajax({ url : filters.ajax_filter, type : ‘post’, data : { action : ‘filter_reports’, // You … Read more

get current taxonomy post with ajax

//$bkcat = $term->term_id; try to call this via post from ajax where you will pass id of category $args = array( ‘posts_per_page’ => -1, ‘category’ => $bkcat, ‘order’ => ‘ASC’, ‘post_type’ => ‘bk-post’, ‘category_name’ => $bkcat, ); $the_query = new WP_Query($args); if($the_query->have_posts()) { ?> $i = 1; while($the_query->have_posts()) : $the_query->the_post(); $a = $i++; endwhile; } … Read more

How to get post from pure frontend AJAX (using only post ID)?

You can output your javascript via wp_add_inline_script(). This way you can set the post”s id and AJAX URL before outputting the code: wp_add_inline_script(‘my-js’, ‘ jQuery.ajax({ \’url\’ : ‘.admin_url(‘admin-ajax.php?action=my_action’).’ data : { \’id\’ : ‘.get_the_ID().’ } });’); Note that you need to hook to an existing js file to be able to add inline script, so … Read more

why does not work ajax that add_action registered in wordpress

The AJAX request is a separate request from the one that renders your page. Your AJAX handler is getting registered on the request that serves the page, but not the AJAX request, which is the one that matters. Move your add_action and function to your theme’s functions.php file, which loads on all requests.

Front end theme options ajax returns 0

You’re sending a bad action for your AJAX request, the action should match with your string next to wp_ajax_: add_action(‘wp_ajax_fend_theme_data_save’, ‘fend_theme_data_save’);, so your action HTML field should be like this: <input type=”hidden” name=”action” value=”fend_theme_data_save” /> See the difference? Your action value should always be next to wp_ajax_ or wp_ajax_nopriv, whatever you’re using. I recommend you … Read more

Send checkbox status with Ajax / JSON and save it

.prop() method return boolean type. True or false. You should send checked value and save it into database. And in HTML get your value and set it to your checkbox. An example you have <input type=”checkbox” name=”test” class=”checkbox” value=”checked”>. You should send to php $(‘.checkbox’).val(); and then place checked attr to html. <?php $checked = … Read more

Need help with ajax

The WordPress Plugin Developer Handbook has background info and code samples of how to use Ajax in your plugin (and themes). Give it a read and it should get you on the right path.