Adding ELSE argument to AJAX Live Search for “No results found”

Try to not using endif and endwhile, just use curly brakets {} to determinate ifs body or add :after elseelse:` Your problem is that you mix two syntaxes. Read this to fully understand how to write alternative syntax https://www.php.net/manual/en/control-structures.alternative-syntax.php add_action(‘wp_ajax_data_fetch’ , ‘data_fetch’); add_action(‘wp_ajax_nopriv_data_fetch’, ‘data_fetch’); function data_fetch() { $post_search_query = new WP_Query(array(‘posts_per_page’ => -1, ‘s’ => … Read more

WP_Query is not received in Ajax

You have use ajaxurl when make post request – it’s right way but it also mean that now $wp_query, in your my__load__more() function, work with your.site/wp-ajax url instead of your.site/taxonomy. That’s why you couldn’t get category name from $wp_query->query_vars. First, I use add_action( ‘wp_enqueue_scripts’, ‘my__enqueue’ ); for enqueue your scripts (see example below). Second, I … Read more

Where to add my PHP codes for AJAX Jquery to work?

Here is a general scenario for adding PHP code snippets in WordPress theme or plugin. Scenario 1: Theme is your custom made theme. In this case, you can add code snippets in your own desired way (and obviously in standard way since you are the author of the theme). Scenario 2: Theme is either premium … Read more

Very weird bug: Ajax for non-admins

Just another suggestion you could try. Rather than doing a separate AJAX call, could you just send it to your script via wp_localize_script? I’m not sure if that would have any effect on your particular bug, but it’s worth a shot? // Make data accessible to scripts wp_localize_script( ‘my-script-handle’, ‘ajax_data’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ … Read more