PHP Warning: Missing argument 2

You are hooking select_age() to wpcf_after_init which more than likely does not accept two arguments. I am not sure why you are hooking into that hook but it is not necessary for a shortcode, nor is there any obvious reason in the code.

wp_ajax action is not run when ajax trigger

I’ve tested your code and it works perfectly. I’ve just declared the dependencies for the JavaScript, so it is loaded correctly after jQuery. This is how I’ve tested it: functions.php function my_resource() { wp_enqueue_script(‘my-jquery’,get_template_directory_uri().’/jqfunctions.js’, array(‘jquery’)); wp_localize_script( ‘my-jquery’, ‘myback’, array(‘ajax_url’ => admin_url( ‘admin-ajax.php’ ))); } add_action(‘wp_enqueue_scripts’, ‘my_resource’); function getsomething(){ wp_send_json_error(‘hey’); } add_action(‘wp_ajax_nopriv_getsomething’, ‘getsomething’); add_action(‘wp_ajax_getsomething’, ‘getsomething’); jqfunctions.js … Read more

AJAX and do_shortcode

Ajax runs without a main WP_Query object and therefor all its APIs that are used to determine the type of page that is being displayed. The code which is responsible for outputting the result of the shortcode is probably checking for is_single() to be true so it will not add output to archive pages. What … Read more

Can’t retrieve any content from Ajax-loaded page

The correct answer is to just do AJAX the right way. Enqueue your script and localize it to add the path to admin-ajax.php: function wpd209588(){ wp_enqueue_script( ‘wpd209588_script’, get_template_directory_uri() . ‘/js/your-script.js?ver=1.0’, array( ‘jquery’ ) ); wp_localize_script( ‘wpd209588_script’, ‘WPaAjax’, array( ‘ajaxurl’ => admin_url( ‘admin-ajax.php’ ) ) ); } add_action( ‘wp_enqueue_scripts’, ‘wpd209588_scripts’ ); In your-script.js, do your AJAX … Read more

Live search from database table

So in php it needs to be: $query = ‘SELECT Location FROM locations’; $result = mysqli_query($link, $query); $rows = array(); while($r = mysqli_fetch_assoc($result)) { $rows[] = $r[‘Location’]; } and jquery ui autocomplete: $(“#location1”).autocomplete({ source: <?php echo json_encode($rows);?>, // this part is only if you want to force autocomplete select change: function (event, ui) { if(!ui.item){ … Read more

Why is the form not updating when I select a new sector from the list?

It looks like only your locations drop-down is triggering the ajax query. I believe the issue is that the javascript is listing for a change event on these elements: ‘#search_keywords, #search_location, .job_types :input, #search_categories, .job-manager-filter’ in the code below (line 178 in http://s195004125.websitehome.co.uk/wp-content/plugins/wp-job-manager/assets/js/ajax-filters.js?ver=1.23.13) $( ‘#search_keywords, #search_location, .job_types :input, #search_categories, .job-manager-filter’ ).change( function() { var target … Read more

How to create a form button that executes a function?

This is a simple example of rendering some items on the front-end that use AJAX to trigger changes in the back-end and update the UI from that response. There are other examples that enqueue scripts so just read up on AJAX and consider this a high level view. REGISTER AJAX/SCRIPTS/CSS add_action(‘init’, function () { // … Read more

What WP-API authentication method should I use to interact with anonymous / not-logged visitors?

In WP REST API v2 use the permission_callback found in the Adding Custom Endpoints Docs. <?php add_action( ‘rest_api_init’, function () { register_rest_route( ‘myplugin/v2’, ‘/author/(?P<id>\d+)’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘my_awesome_func’, ‘args’ => array( ‘id’ => array( ‘validate_callback’ => ‘is_numeric’ ), ), ‘permission_callback’ => function (WP_REST_Request $request) { if ( current_user_can( ‘edit_others_posts’ ) ) { … Read more