Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Ajax - The core of WordPress uses Ajax only in the administration screens. For instance, Ajax is used for instant updates when you are doing comment moderation, and when you are adding and deleting items from lists such as categories, blogroll, and posts; Ajax is also the technology behind the auto-...

0
votes
1answer
23 views

How can i get the same ajax result using WP REST API instead of admin-ajax?

I have been told that admin-ajax is outdated now and it's better to use REST API instead but I was wondering how can I get the same result of this code which generates a button with a link based on ...
0
votes
1answer
37 views

Why i can't get custom fields value or post ID via Ajax?

I wrote a code that generate a link based on the visitor location and it worked perfectly but i discovered that the generated code get cached since i'm using a full page caching so i though to solve ...
0
votes
1answer
18 views

How to call a function from functions.php with ajax?

I'm wondering how can i call a function from functions.php and print it with Ajax in a specific place (woocommerce_before_add_to_cart_button). I know i can simply add my function in add_action like ...
0
votes
0answers
13 views

Random photo size & arrangement for portfolio

I want me make my portfolio page to show different style when the user refresh my page. the picture will display different size randomly e.g. the square image will remain the square image but the ...
-1
votes
1answer
25 views

How to prevent those PHP variables from being cached on WordPress?

I'm using this code in functions.php on WordPress to generate an affiliate link based on the visitor location, It's working perfectly but the problem is that if page caching is turned on (W3 Total ...
1
vote
2answers
36 views

Prevent page reload after ajax form submission

I'm trying to submit a form in wordpress with ajax. But after the first submision the page itself is called again. My Form <form class="et_pb_contact_form clearfix" method="post" action="" id="...
0
votes
0answers
14 views

update_user_meta() not working in ajax function

My goal is too allow users to upload their own avatar images to my site. I can successfully upload files to my site but when I try to add them to the user meta it does not add the meta entry. Here ...
0
votes
0answers
34 views

Retrieve data from MySQL into dropdown using AJAX

I'm trying to retrieve data from MySQL into dropdown using AJAX, but the results of the dropdown are not displayed. Here's the snippet: Form: <?php global $wpdb; $aName = $wpdb->get_results("...
0
votes
0answers
11 views

How can I show hidden products when filtering in WooCommerce

I am looking for a way to show the children of a grouped product when WOOF - WooCommerce Products Filter is triggered. Before then I only want to show the parent product. Currently when on the /shop/...
-1
votes
1answer
23 views

Most efficient way to get custom database records from 20 buttons and 20 tables?

I have 20 buttons on a member protected wordpress page and each button gets a random record from a different custom table in the wp_ database. @janh provided a solution here to get the random record ...
0
votes
0answers
10 views

Trigger action via button

I am using wordpress 4.9.8 and PHP 7.1.8 I have added a button to the new post screen: I am trying to trigger the button the following way: add_action( 'media_buttons', 'add_my_media_button', 99 ); ...
0
votes
1answer
16 views

How to Access custom database content with AJAX onClick refresh of div inside member-only wordpress page?

The use case is providing the user with 20 different buttons on a single login protected page, each button is a category from a custom database table and the content is shown in a textarea element on ...
0
votes
0answers
12 views

Redirect sub pages but load them with ajax

I redirect subpages. (site.com/page/2 to site.com) But then when loading these subpages with ajax (load more), they do not load. How to both redirect the subpages but also load them with ajax?
0
votes
0answers
13 views

WooCommerce - updating address fields in registration form

I've added some WooCommerce checkout form fields to the registration form, since my site requires customer to provide their billing address during registration. // Custom function to display the ...
0
votes
0answers
41 views

How do I use AJAX Query in my posts loop?

I have this function in my functions.php. All the AJAX and Query is working but displays the results of the loop right below the AJAX filter. I want the query loop to display in my main theme's ...
1
vote
1answer
99 views

Ajax stops working when logged in?

I have implemented ajax in the website add_action('wp_ajax_wppl_function', 'wppl_function '); add_action('wp_ajax_nopriv_wppl_function', 'wppl_function'); But this works without any issue if i log ...
6
votes
2answers
2k views

Why is die() used at the end of function that handles an Ajax request?

What could go wrong if I am not using die(); after the function that handles an Ajax request? I have noticed that almost all the WordPress Ajax-based code is using it.
0
votes
0answers
6 views

Validating textarea, Before sending the value to the DB

I have a textarea that I want to validate: <form method="POST"> <textarea id="textarea" name="textarea"></textarea> </form> Sending the value using Ajax: $.ajax('ajaxurl'...
0
votes
0answers
15 views

Ajax to know if it's frontpage and $do_not_duplicate?

I'm changing my frontpage to "lazy load" content. And in functions.php I have coded a function that creates the content with the content; headlines, preambles, images. The problem is that this content ...
0
votes
0answers
10 views

How to include files in the loop via ajax

I create plugin and I need to include multiple files via ajax. When I don't use loop this code work: include_once( trailingslashit( plugin_dir_path( __FILE__ ) ) . 'sections/a.php' ); When I try to ...
0
votes
0answers
25 views

Displaying dynamic pages inside another page in wordpress

I have a webpage that is built using visual bakery (shortcodes) in wordpress, now i want to display that page inside my account/downloads page such that if a condition is met then display page ...
0
votes
0answers
38 views

i can't use wordpress functions in ajax loaded php file

I want to make a chained select like this brand > model for that i make a file named cat.php in my themes folder that contains this code <div id="categories"> <?php $args = array( ...
0
votes
0answers
10 views

How does Woocommerce load the cookies into an AJAX request?

I'm building a plugin to allow users to use their own domain on a Woocommerce store. Everything works except for requests to ?wc-ajax=get_refreshed_fragments. On the primary domain, Woocommerce sets ...
0
votes
1answer
49 views

How to call a PHP function with Ajax when the user clicks a button

I'm developing a wordpress site using custom templates/themes, but I'm having trouble. I want to use Ajax to call a function when a user clicks a button. On one page, I have a button like so: <p ...
0
votes
0answers
27 views

Ajax call on class returns old data

I'm facing this issue since days and I don't know what to do, my problem is the following. For example, I have this class: class My_Class { public $attr; public function __construct() { ...
0
votes
0answers
29 views

WP admin ajax Pagination issue

Hello i am using ajax to filter my custom post type based on categories by ajax after ajax filter i am getting my desire result but after ajax call pagination not working. this is giving me this ...
0
votes
0answers
16 views

Show ajax form resuslts in page

I have this multi-steps form which should filter through user's choices and give back a list of posts, related to that choices. I'm trying to do that with ajax, but even if I get the response in ajax ...
0
votes
0answers
14 views

Ajax duplicate multiple inline data checking from database

I am trying to make a form with multiple same type field (i.e. title) in Wordpress. In that case I need to ensure that no duplicate data is being attempted to insert before the form is submitted. I ...
3
votes
4answers
191 views

WordPress post sorting with AJAX

I am having a search result page for custom post type. I want to have a ajax sorting feature. Eg sort the post by taxonomy without reloading the page. A very basic example will help. Thanks The ...
0
votes
0answers
19 views

enqueue style using admin-ajax.php

Actually I’m making a generic personnal template with customization from the backend; something like in the premium themes. So I made a “theme apearance options page” with ACF. I added fields like “...
0
votes
0answers
20 views

How to safely pass post_id and user_id via AJAX to the backend (prevent user from changing it via JS)?

I'm having code (user rates post) where I'm passing user_id and post_id via AJAX to the back-end. My concern is that user can change values in JS and pass another’s user id or post id. How do I ...
0
votes
1answer
24 views

How to continuously send feedback via AJAX responses to my client?

I have a mechanism that's triggered via AJAX and now have decided to optimize it by batching each main call into an AJAX call to avoid timeout issues (so the script doesn't run the 5 main processes I ...
0
votes
0answers
33 views

Custom theme admin-ajax.php 400 (Bad Request)

I am trying to load posts via ajax in WordPress but I am getting admin-ajax.php 400 (Bad Request) error. I have used the same code in one other website and it was working there but here in this ...
0
votes
0answers
22 views

How to handle ajax Request in a complex-structured plugin?

I've been looking how to handle ajax requests in a plugin with wordpress. I have a found a cool article about this in the codex. I think I got the basics but it seems I can't get my handler function ...
0
votes
0answers
36 views

Update cart object's custom field using ajax

I have added a custom field in my cart object when a product is added to the cart using this filter: add_filter( 'woocommerce_add_cart_item_data', 'custom_field_add_cart_item_data', 10, 2 ); ...
0
votes
1answer
27 views

ajax polling with admin-ajax.php

Is it possible to do ajax polling in WordPress with admin-ajax.php for example every 300ms? I have tried this and it appears that doing the ajax request with admin-ajax takes longer than the ...
0
votes
1answer
43 views

Search filter by Post title OR Meta Title Value [duplicate]

I am trying to search Movies by it's Post title OR Meta Title value. But it is not working, it only search's by Meta value. I need to search by Post title as well and i.e check if the keyword is ...
0
votes
0answers
20 views

How to do polling of session variable with ajax in WordPress admin plugin for progress bar

I'm working on a plugin. I have a somewhat long running php process and I am trying to show a progress bar by polling a session variable with ajax and displaying on the front end. I previously had it ...
0
votes
0answers
41 views

Passing values AJAX Callback With JSON (PHP)

I'm making a search filter with a form showing a few select dropdown values and one true/false input. The dropdown values populating the form are ACF fields for a custom post type ARTWORK. The ...
1
vote
2answers
31 views

WP_Query ajax loader detect end of posts

I built the ajax loader as follows. How can I detect when it reaches the end of all posts? So that I can make the "More" button to disappear, or not clickable anymore. In page template: WP_Query ...
1
vote
0answers
22 views

Storing data in wordpress database from ajax call from different website

What I am trying to do is that, I am providing users with embed code for videos...now with these embed codes I am sending a number, once the user watches the video, I am sending that number back to my ...
0
votes
0answers
42 views

JQuery - Uploading image using Wp Rest API

I am trying upload an image to the wordpress media library with jquery from localhost. Here is my code function get_image_id(filename) { var img = new Image(); img.src = filename; //...
0
votes
0answers
15 views

Filter a WP_Query with search box (AJAX)?

I have a page template where I call in a custom post type like so: $caseArgs = array( 'post_type' => 'cases', 'post_status' => 'publish', 'posts_per_page' => -1, 'order' => '...
0
votes
0answers
39 views

admin-ajax returns 400 (Bad Request)

I'm facing an issue and I can't get the reason, I tried to print the variables and check for typo errors, But couldn't find any. I send an Ajax request to admin-ajax: function update_order() { ...
0
votes
0answers
19 views

Syntax error on query_vars while handling with Jquery

I am building my own ajax load more. It works good on main query or other custom queries. But when i try it in search page query, browser console gives syntax error. Here is query args: <?php $...
0
votes
0answers
20 views

Save Search Criteria notification

I am trying to simply figure out how, after a user has saved a search on my site and wishes to get notified if anything new matching that search criteria has been added, can I then re-run the saved ...
0
votes
0answers
52 views

Action in Ajax request does not run for some user roles

I have an ajax POST request that looks like this: var data = { action: 'like_prof', id: profID, }; $.ajax({ method: "POST", url: ...
1
vote
1answer
20 views

Ajax Wordpress Login needs to be stayed in current page Url without redirecting

Currently i am creating a login system based on ajax in wordpress after successful login it was redirecting to homepage but what i need is it needs to be stay in the current page where the user is ...
0
votes
1answer
62 views

how to enable ajax on submitting of contact form 7?

Actually i am try to show the short code of contact form 7 in the popup window . but the The form appears in the popup window when i submit the form page loads. i want to stop the page after ...
2
votes
1answer
28 views

WP Ajax Action Not Picking Up Query String Parameter

Not sure why this isn't working... my action is being passed and the right function is firing from my ajax, but the callback isn't receiving my query parameter. My ajax (using bloodhound.js running ...