You can use the WordPress functions apply_filters
and add_filters
to store and retrieve data, like so:
// The filter callback function.
function so_wp_380975_get_user_args( $array ) {
// (maybe) modify $array.
// for now, we just return the array
return [
'meta_key' => 'mycred_default',
'orderby' => [ 'meta_value_num' => 'DESC' ],
'order' => 'desc',
'number' => 10
];
}
add_filter( 'get_user_args', 'so_wp_380975_get_user_args', 10, 1 );
// get the stored args from the filter
$args = apply_filters( 'get_user_args', [] );
Note that you can do a lot more, such as passing additional arguments to the filter to modify the args – or a default value, in case the filter returns nothing.
https://developer.wordpress.org/reference/functions/apply_filters/
Related Posts:
- The correct method to pass query vars in AJAX using ajaxurl
- Any possible way to make $wpdb->get_results() return anything else than array?
- unable to use ‘new WP_Query’ in AJAX call
- Shortcode to pull posts
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- WordPress Conditional / Multiple Taxonomy Query
- My Custom Post Type AJAX Query is Returning no posts – why?
- Offset with ajax load more posts duplicates
- Can I use the same nonce for multiple requests on the same page?
- wpdb::prepare was called incorrectly
- Real time Duplicate title check
- Load custom field value into div with AJAX
- Accessing a random image via ajax
- Making a follow button, Ajax not talking to php
- my function doesn’t return my post from today
- Ajax form submit within a Post Metabox
- WordPress File handle – fopen, fwrite not working with $.ajax or $.post Jquery
- Stumped – Ajax Response Returns 0
- Multiple choice in a custom taxonomy
- doing an ajax request always outputs 0
- Trying to implement Ajax comments in WordPress, getting WP error
- Can’t search posts using WP_QUERY inside AJAX Function
- Woocommerce add to cart quantity buttons with AJAX
- class click counter save number
- Get stock by custom meta field on all Woocommerce variable products
- WP Query with custom Shortcode
- wordpress count link clicks by ip address
- Ajax – Call to undefined function get_option()
- WordPress 3.2 query_posts and pagination, permalinks issue
- only show container with next/prev links if they exist?
- Ajax load more posts with multiple tax query
- Ajax call not working
- WordPress Sending data to Ajax with select option
- PHP 8, AJAX mail form to function.php doesn’t work
- Ajax request not sending to server and returning – wp-admin/admin-ajax.php 400
- Repeating admin-ajax.php not found error in admin
- populate form fields in a loop with ajax
- Long running queries
- How to pass Select value from Javascript to PHP to generate select option on change
- how to make custom ajax handler?
- Plugins not working on AJAX requests
- How to disable controls in theme customizer?
- register_taxonomy() take much queries
- AJAX button action in foreach
- WordPress ajax-action failing because of newline in response
- Making an AJAX call to refresh a table
- load ajax using admin-ajax.php
- Ajax button not working
- Simple AJAX notification when the new post is added to the database
- WordPress query undefined offset in loop
- PHP -> SQL Query with Summing
- How to hide posts of a specific custom category in WordPress?
- Calling PHP Scripts in Ajax that are in PHP Snippets
- Simple jQuery AJAX Request fails to run PHP Script
- Allow user to Upload image and manipulate it on the frontend
- Echo array value
- Execute Jquery when a specific page in my plugin is loading
- calling admin-ajax.php from admin-ajax.php
- AJAX function not working [closed]
- what does $options = get_option(‘test_theme’); do?
- Query pulling a single post per month
- SQL error with custom query
- Validating an email input from form field before submit using JQuery, AJAX, and PHP
- Ajax on the Administration Side of plugin – wp_localize_script – how to pass value from JQuery to PHP function in class?
- Advanced Query posts
- How can I check that the acf field value is not a duplicate when adding a post?
- Submit remote form to wordpress REST API and save data to custom post type
- Filtering custom posts by using checkboxes for taxonomy in an ajax loop always gives server 500 error
- wp_set_object_terms returns 500 error when called through AJAX function
- How can i send id of the currently posted form data through json response in custom wordpress plugin?
- Cannot successfully execute AJAX script to call function.php specific function. Using XAMPP localhost to test
- autocomplete in wordpress using ajax with json-data
- Contactform7: display results from CURL
- ajax polling with admin-ajax.php
- Remove item from post_meta array via AJAX
- Query doesn’t display text data with apostrophes
- wp_send_json erase last value
- How to make a parent page for author.php?
- defined (‘ABSPATH’) false after AJAX post to other PHP-file
- How to load WP_Editor JS files manually (with AJAX)?
- A javascript function that simply runs a php function on the plugin
- wordpress ajax pagination
- how use php query in AJAX jquery
- wp_delete_comment is doing nothing
- 403 (Forbidden) delete file image in themer folder
- 500 (Internal Server Error) of external php file
- Use jQuery and AJAX to get HTML
- Problems with plugin that fetches data from database with ajax
- Dynamic Gallery
- Execute PHP code in Javascript onclick
- best way to communicate between php and jquery/javascript
- Loading a post’s content, into a div outside the loop, when it’s title is selected in a list
- AJAX: WordPress filters inside $html do not work as intended
- Why not showing all post by default in my jquery filter
- Jquery autosave text area after typing
- Pass a PHP variable (loop-audio.php) to jQuery function (js/script.js)
- How to Set Page Pagination Using Ajax JQuery – WordPress
- How to pass and validate nonce in custom REST routes
- ajax problems on loading page [closed]
- Woocommerce – Include custom user meta in order ‘filter by registered customer’ Ajax search