call shortcode in javascript

Javascript code is running in the user’s browser and not on your server (where your wordpress content resides). You could use ajax to call the function which the shortcode is pointing to. Here is how I handle AJAX calls with WordPress: 1) I use a jQuery ajax function to call the wp-admin/ajax.php jQuery.ajax({ url: yourSiteUrl … Read more

Load tinyMCE / wp_editor() via AJAX [duplicate]

your post here helped me figure a solution. Along with the mceInit property, I also had to retrieve the qtInit that wp_editor generates as well. The following is the relevant code within my class. Basically I have wp_editor run so that the javascript is generated. I use hooks to retrieve the javascript, so that I … Read more

Admin Notification after save_post, when ajax saving in gutenberg

Presenting Notices Gutenberg provides a mechanism for displaying notices in the form of the Notices Data package. In Gutenberg’s editors, the package’s selectors and action creators are exposed on the core/notices store, and can be accessed by any standard means therein, e.g.: useDispatch( ‘core/notices’ ) hook in functional components (including the edit() function of a … Read more

Ajax requests without JQuery

Coming back to this on a new application. I just solved this using Angular, and a similar approach could be used with vanilla JS. First, give Javascript access to the admin-ajax.php URL, something like: echo “<script type=”text/javascript”>var ajaxurl=””.admin_url(“admin-ajax.php’).”‘</script>”; Next, in functions.php, register the action you want the Ajax to perform: add_action(“wp_ajax_infiniteScroll”, “infiniteScroll”); add_action(“wp_ajax_nopriv_infiniteScroll”, “infiniteScroll”); …and … Read more

How to check if new posts have been published since page load?

Determining the current time There’s the current_time() function in core that allows to pass three different values as first argument and gmt (the offset) as second argument. About the 1st: mysql -> gmdate( ‘Y-m-d H:i:s’ ), human readable e.g 2004/07/8 13:35:19 timestamp -> time(), the UNIX timestamp for e.g. 1335939007 A custom argument that is … Read more

ajax category filter

Not sure if you’ve solved this or not but I was looking for a way to embed this within a page and filter posts by category. I got this working so it displays all categories and the posts related. Put that in functions.php function ajax_filter_posts_scripts() { // Enqueue script wp_register_script(‘afp_script’, get_template_directory_uri() . ‘/js/ajax-filter-posts.js’, false, null, … Read more

AJAX function returning -1

You are passing ‘eu_custom_query’ as the action in your AJAX. It should be ‘custom_query’. You decide the action name, when you add the action i.e. ‘wp_ajax_my_action’ would be called ‘my_action’ You are confusing it with the callback method. Hope that makes sense. p.s. to fix your code change: add_action(‘wp_ajax_custom_query’, ‘eu_custom_query’); add_action(‘wp_ajax_nopriv_custom_query’, ‘eu_custom_query’); to: add_action(‘wp_ajax_eu_custom_query’, ‘eu_custom_query’); … Read more

admin-ajax.php returns 0. How do I debug it and fix it?

Enable Debugging WordPress has constants defined in wp-config.php where you can print errors to the screen and log them in a separate file located /wp-content/debug.log. It looks like this: define( ‘WP_DEBUG’, true ); define( ‘WP_DEBUG_DISPLAY’, true ); define( ‘WP_DEBUG_LOG’, true ); You can then print your own information to the debug log at specific point … Read more