Loading Posts & Category with Ajax

Sure, the get_template_part() function can be called multiple times referencing to different files, so if you have a file in the partials/-folder, all you have to do is add a second function call here. function load_cat_posts () { $cat_id = absint($_REQUEST[‘cat’]); $args = array ( ‘cat’ => $cat_id, ‘posts_per_page’ => 10, ‘order’ => ‘DESC’ ); … Read more

WP_query offset seems to be counting draft post – AJAX load more

There is a argument for posts query is post_status. It’s values are like below- $args[‘post_status’] => array( //(string / array) – use post status. Retrieves posts by Post Status, default value i’publish’. ‘publish’, // – a published post or page. ‘pending’, // – post is pending review. ‘draft’, // – a post in draft status. … Read more

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

Convert to shortcode?

Look into the add_shortcode function, which can be part of the plugin (although I don’t recommend modifying other’s plugins, since your changes will be overwritten if they send out an update. So you would add this function to your ‘child theme’ function.php function add_my_shortcode() { add_shortcode(‘your-shortcode-name’, ‘the_function_for_your_shortcode’); } add_action(‘init’, ‘add_my_shortcode’); ..and here is the function … 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

Adding custom cart price with Ajax in wordpress

Try to change your add_custom_price_callback() as follows. Untested but should work. function add_custom_price_callback() { $custom_price = intval($_POST[‘p_m’]); $target_product_id = intval($_POST[‘s_o_v’]); foreach ( WC()->cart->get_cart() as $key=>$value ) { //Single product if ( $value[‘product_id’] == $target_product_id ) { $value[‘data’]->set_price($custom_price); } //For variation if ( $value[‘variation_id’] == $target_product_id ) { $value[‘data’]->set_price($custom_price); } } //to check if is work … Read more