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
- Ajax call return 404
- How to add a do_action on refreshing of WP customizer?
- How to pre populate a form field with a link of a current user’s author profile?
- Refresh table data with Ajax
- Two queries for a WP_User_Query search work perfectly apart, but not together
- How to pass Select value from Javascript to PHP to generate select option on change
- Trying to get a PHP variable defined in a custom post into a javascript file. Null value. Using wp_localize_script
- get_children displaying images removed from the page
- Setting value of session with Ajax not working
- AJAX success response is not working but it’s saving my changes
- how to make custom ajax handler?
- [jQuery]Adding shortcode
- Query if audio attachment AND/OR custom field
- Display parent and child taxonomies in separate drop down select fields
- Show success or error messages in Ajax response to WordPress custom registration form
- How to add a Custom Mailchimp AJAX Newsletter Subscribe Form
- Using $wpdb (WPDB class) ‘replace’ with multiple WHERE criteria problem
- Plugins not working on AJAX requests
- Fancybox type popup window that’s not an iframe
- Using Select HTML in Bootstrap Popovers
- How to disable controls in theme customizer?
- register_taxonomy() take much queries
- Can I use a jQuery Ajax request in Code Snippets Plugin for WordPress?
- how to update and display an option without reloading the page
- WordPress SQL injection
- How do I Import / Upload Files with jQuery AJAX?
- WordPress admin-ajax.php 400 bad request
- Which is the correct way to conditionally enqueue a CSS file?
- WordPress Ajax Call inserting data but success response false
- Loading php file with AJAX in WordPress frontend
- Odd / Even posts add class minus first post
- wp ajax return 0
- Ajax contact form return 0
- WordPress plugin: render only page content using ajax call
- AJAX – Returning Two JSON Objects with One PHP Function
- Pull GetOption() variable into jQuery dynamically created html
- Get the URL of the page from which an ajax request has been launched within ajax callback
- admin-ajax Firing Error 400 When Logged In
- AJAX button action in foreach
- is_user_logged_in() not working in AJAX validation call
- Unset session variable on page reload / setup but exclude AJAX
- Parse error: syntax error, unexpected ‘}’ on get_the_author_meta [closed]
- Add Ajax Hooks and Call from Custom Template PHP
- WordPress ajax-action failing because of newline in response
- Making an AJAX call to refresh a table
- HTML escaping data with ajax requests
- WordPress Ajax Always returning 0
- How to list commenters and days since last commented
- Using data sent via AJAX in multiple functions on a WP plugin
- Problem with AJAX in wordpress plugin
- load ajax using admin-ajax.php
- How to add div blocks after certain set of post
- Ajax button not working
- How to overwrite orderby with add_query_var
- Can’t update multiple rows with $wpdb query
- Function won’t run onclick using Ajax
- How to keep track of when a vote is cast?
- working with term_relationships table
- WordPress plugin admin page – using WordPress function in linked php file
- Load Posts on Click via Ajax into a DIV
- set post limit at load more ajax wordpress
- Use value from Ajax call in PHP function
- Woocommerce with Lazy Load php and ajax
- How to deal with too many $_POST variable conditions from ajax request at backend? [closed]
- Simple AJAX notification when the new post is added to the database
- AJAX wp_insert_user WORKS but responds with “The site is not enabled”
- Short code template + ajax
- WordPress query undefined offset in loop
- Ajax filter button display all posts
- Compare $_POST returned values with term array
- Is it possible to create new user from external form using REST API?
- Any ideas why I am getting “I’m getting “wp-admin/admin-ajax.php 401 (Unauthorized)”
- WordPress REST API register_rest_route give a 500 error
- Issue with custom loop in Archive page
- How to display SQL query that ran in WC_Order_Query?
- Custom Post type slider with thumbnail navigation
- How to use AJAX to call php page with parameter
- Get related product based on subcategory selected from category id with ID 142
- A $_POST should occur when submit form but is not?
- Parse error: syntax error, unexpected ‘}’ [closed]
- When echo follow Ajax button inside Ajax pagination template not working?
- My jQuery Ajax form submit is still refreshing page?
- jQuery Ajax PHP function call returning [object Object]
- admin-ajax GET response bad request
- Ajax search shows all results when user empties input?
- Why i can’t get custom fields value or post ID via Ajax?
- 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
- javascript variable to wordpress php variable
- Post not populating for custom post type based on category selection
- SOAP Request/Parsing XML From wp_send_json_success