Parsing php string in jquery [closed]

Well it seems @JacobPeattie mentioned to use json, I just echoing that. First json encode the variable $array = json_encode($out); Then send this value echo ‘<div data-ad = ‘.$array.’ class=”ash_loadmore”><span>LOAD MORE</span></div>’; To get that echo json_encode($_POST[‘ad’]) I think that’s it.BTW you don’t have now that string problem as the output will be like this {“footer-insta”:2,”sidebar-1″:3} … Read more

WordPress loads Jquery Automatically – is my idea correct to add it to the footer?

You shouldn’t enqueue jQuery by manually using wp_enqueue_script(‘jquery’);. WordPress can enqueue it for you the right way. All you have to do is to declare jQuery as your script’s dependency: wp_enqueue_script( ‘my-script’, get_template_directory_uri() .’/my-script.js’, array(‘jquery’), null, true ); You can pass an array of dependencies as the 3rd parameter. Also, by setting the 5th parameter … Read more

wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated

Don’t bother fixing your AJAX callback, there’s already a REST API endpoint that’s well tested and does all of this out of the box: example.com/wp-json/wp/v2/zen_page So lets enqueue a helper script to give us the URL and a security token/nonce: wp_enqueue_script( ‘wp-api’ ); You will must enable the REST API for your custom post type … Read more

Filter categories of posts with checkboxes

I was able to solve this by using Ajax. First I’ve changed my query args: $args = array( ‘post_type’ => ‘html5-blank’, ‘posts_per_page’ => 5, ‘paged’ => $paged, ‘category_name’ => get_query_var(‘category_name’) ); Then I made template where my content would change by injecting it with Ajax like this: var $vbPosts = $(‘#vb-posts’); var videoCats = { … Read more

Add custom setting that uses radio button to WP Gallery

I had the same problem and got it finally to work. Based on the thread you have followed, you now have to extend the “update” function of the WP core /wp-includes/js/media-views.js. Go to the “jQuery(document).ready(function()…” part of the ‘print_media_templates’ action and try this: <script> jQuery(document).ready(function() { wp.media.view.Settings.Gallery = wp.media.view.Settings.Gallery.extend({ // add your custom options template … Read more

Ajax return code 400

Here’s a base snippet I use for AJAX submits in WordPress, it might help you out: <?php if (isset($_POST[‘my_theme_ajax_submit’])) if ( wp_verify_nonce( $_POST[‘nonce’], ‘my_theme_ajax_submit’ ) ) my_theme_ajax_submit(); function my_theme_ajax_submit() { // do something // some php code that fires from AJAX click of #fire wp_mail( ‘[email protected]’, ‘my_theme_ajax_submit() fired’, time()); wp_die(); } ?> <button id=’fire’>Fire Something</button> … Read more

WP Admin missing icons, numerous JavaScript errors, but only when SCRIPT_DEBUG is false

Do you load own javascripts into the admin? If i recall correctly, if SCRIPT_DEBUG is set to true, the javascripts are not concenated, but loaded seperately. So if a custom javascript doesn’t play well being concenated, this can lead to the whole concenated javascript being corrupt and not being run correctly. Try removing the added … Read more