Full-Ajax Theme: parseJSON error while building a JSON object from a WordPress custom template

Replacing all the specific the_content() functions, or the_ID… etc by the getters equivalent seems to fix the problem. Here the solution: <?php $o = array(); $o[ ‘title’ ] = wp_title( ‘|’, false, ‘right’ ); $o[ ‘type’ ] = ‘single-project’; //ob_start(); $article=”<div id=”container” class=”content-area project-content”>”; $article .= ‘<main id=”main” class=”site-main” role=”main”>’; while (have_posts()) : the_post(); $article … Read more

Using AJAX to return search form results

There are two issues in your code You need to add script in wp_enqueue_scripts hooks like this – add_action(‘wp_enqueue_scripts’, ‘my_custom_js_script’); function my_custom_js_script() { wp_register_script( ‘ajax-productSearch’, get_template_directory_uri() .’/js/ajax-product-search.js’, array( ‘jquery’) ); wp_enqueue_script( ‘ajax-productSearch’ ); wp_localize_script( ‘ajax-productSearch’,’the_ajax_productSearch’, array(‘ajaxurl_productSearch’ => admin_url(‘admin-ajax.php’))); } The second issue is that, you need to add action argument in your jQuery.ajax data. If … Read more

Load custom formatted comment with AJAX: reply link isn’t rendered?

It appears you can get max_depth from the options via get_option(‘thread_comments_depth’): function prefix_submit_ajax_comment(){ $comment = wp_handle_comment_submission( wp_unslash( $_POST ) ); …handle errors and get $comment_depth… $GLOBALS[‘comment’] = $comment; $GLOBALS[‘comment_depth’] = $comment_depth; $args[‘max_depth’] = get_option( ‘thread_comments_depth’ ); // solution op_format_comment($comment, $args, $comment_depth); }

How to securely add an Ajax button to a WP Admin page?

In this answer I created 2 buttons which are visually disabled and get an invalid nonce before submitting. <?php /* Plugin Name: Ajax Example */ add_action( ‘admin_notices’, ‘my_action_button’ ); define( ‘MY_ACTION_NONCE’, ‘my-action-‘ ); function my_action_button() { $id = 4321; $data = array( ‘data-nonce’ => wp_create_nonce( MY_ACTION_NONCE . $id ), ‘data-id’ => $id, ); echo get_submit_button( … Read more

Error 400 bad request using admin-ajax.php

The hook prefix is wrong — it should be wp_ and not admin_: add_action( ‘admin_ajax_nopriv_pedido_clientes’, ‘enviar_pedido_clientes’ ); add_action( ‘admin_ajax_pedido_clientes’, ‘enviar_pedido_clientes’ ); So the correct code is: add_action( ‘wp_ajax_nopriv_pedido_clientes’, ‘enviar_pedido_clientes’ ); add_action( ‘wp_ajax_pedido_clientes’, ‘enviar_pedido_clientes’ );