I want to make a post api call once a post or page is published/updated and show a javascript alert box saying ‘Post has been published/updated’

If you only want an alert then why do you write it in a separate file and enqueue it? You can directly write it inside the invoke_save_post function using echo “<script>alert(‘Api called’);</script>”; or if you want to write it in a separate file then you have to write your alert inside the function and call … Read more

wp.media gallery collection sometimes undefined

So i finally figured it out, the gallery switches modes sometimes, even without clicking anything (not completely sure what actually happens, I have no idea about Backbone tbh.) Here is what now works for me: if(wp.media.frame.content.get(‘gallery’).collection) { wp.media.frame.content.get(‘gallery’).collection.add(formatted); } else { wp.media.frame.controller.content.get(‘gallery’).collection.add(formatted); } The else-line won’t work when initially loading of media library, so I … Read more

duplicate posts with ajax load more wordpress

Firstly your cat parameter expects an array and you’re passing a json string to it… You need to json_decode back your array of posts to run through the query. Secondly, you are using query_posts() which if you look at the codex page reads: Note: This function will completely override the main query and isn’t intended … Read more

how to add a custom javascript file to our theme

Having this issue for months and I got it now running when I posted the question here. the issue is that the wp_enqueue_script needs to have the script file register first. So I have it working this way! if (! function_exists(‘custom_jsfiles’)) { add_action(‘wp_enqueue_scripts’, ‘custom_jsfiles’); function custom_jsfiles() { wp_register_script(‘custom_js’, get_theme_file_uri().’/mytheme/custom-js.js’); wp_enqueue_script(‘custom_js’); } } ######################## updating the … Read more