Based on comments in this thread, I think using a WordPress transient to store the value of $myvar
is the best solution in my case. One reason is because in my case, the browser does not need to know the value of the variable.
Here is some more information to make an informed decision in your specific use case:
- This separate Stack Exchange question has an answer which provides more information on all the ways to persist data in WordPress, including the use of transients.
- This link has more info on specific options.
- PHP sessions don’t seem to be suggested for WordPress uses (see the previous two links). But this link has more info on them.
Related Posts:
- username_exists() function can’t be access without logging in
- Can i check if user is doing any ajax request?
- How to add default images into theme customizer image control?
- Is the regular ajax request method safe or I should use admin-ajax.php?
- Validate a users email address when using gmail to register
- Click loads template via ajax
- How to speed up admin-ajax.php in wordpress
- get post based on category chosen in drop down – The ajax method
- How to store data from multiple forms using ajax and php
- 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
- Why ajax doesn’t work on certain wordpress hooks?
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- dynamic dependent select dropdown
- how to make custom ajax handler?
- How to disable controls in theme customizer?
- is_user_logged_in() not working in AJAX validation call
- Using data sent via AJAX in multiple functions on a WP plugin
- Function won’t run onclick using Ajax
- Simple AJAX notification when the new post is added to the database
- Why i can’t get custom fields value or post ID via Ajax?
- Post not populating for custom post type based on category selection
- How to get post category list as select in front-end?
- Is there a hack for using is_page() within the function.php file?
- Execute Jquery when a specific page in my plugin is loading
- AJAX function not working [closed]
- Disclaimer that will show every refresh of the page
- Database entry removed on browser refresh, Ajax PHP jQuery
- Store ajax data in PHP variable
- Multiple AJAX handler functions conflict in functions.php
- Ajax filter with loadmore button
- How to change this ajax function to submit to the default wordpress content area instead of the custom field ‘seller notes’?
- register_block_type is not working properly
- get_the_author_meta( ‘ID’ ) just return 1
- Update $wpdb query with AJAX
- WordPress Ajax filter: Create two loops for different output styles?
- Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
- Offset with ajax load more posts duplicates
- ajaxurl usage for a custom function
- How to call a function from functions.php with ajax?
- Custom Post type Ajax search results
- Find the method which AJAX GET calls
- AJAX Returning Way Too Many Posts
- wordpress ajax return 0
- wp_delete_comment is doing nothing
- Modify category archive page loop on functions.php
- Registration form not registering First and Last name
- Modify php code to pass a page id as a parameter in order to create a breadcrumb
- ajax form function error
- AJAX: WordPress filters inside $html do not work as intended
- Where to include php files in wordpress and how to refer to them later [closed]
- How to get the original price of the product in woocommerce?
- How to add 2 posts under another post? Formatting should be intact
- Get widget settings function?
- enqueue multiple Google fonts with multiple weights and styles (italic)
- What is the fastest way to load PHP functions that are only used in one theme template?
- How to make custom total price reactive in navigation
- Adding tawk.to code just before body tag on functions.php file
- Creating a Multi-Level Associative Object Using AJAX
- add_action shortcut?
- Get page that displays all children of taxonomy parent
- Why ajax doesn’t work on certain wordpress hooks and reload the page instead?
- Function to capture a value and store it in a variable
- How to add a do_action on refreshing of WP customizer?
- Adding a widget function into the php theme file
- My new button is in the wrong place
- Checking array against author id in loop
- Call to undefined method – Download Monitor
- How do I link a button I created in theme customizer to a function?
- Tell WP register script to load a script only when the entire page is loaded
- Can’t save php string to a custom field
- get_template_directory adding FTP root folders in urls
- Remove extract from function
- Undefined offset: 3 in custom function
- WordPress REST API register_rest_route give a 500 error
- Changing the order of custom fields in the dashboard for Woocommerce variable products [closed]
- Proper way to use WordPress function with AJAX PHP file
- call_user_func_array() expects parameter 1 to be a valid callback, function ‘———-‘ not found or invalid function name
- Can/should we delete wordpress cron jobs with no action?
- Display Visual Composer shortcode if a post belongs in specific categories
- Add Featured Image to Existing Post
- Flushing the slug base has no effect and does not change
- Multiple cron jobs vs daily cron job doing multiple things? Which one yields better performance and scalability?
- wp_ajax_ 400 Bad Request
- Handling form actions in WordPress
- Set user status to absent on WordPress
- Shortcode’s output to use as other shortcode’s parameter
- Displaying POST content with HTML tags and all
- Showing wordpress latest post thumbnails in slider with auto increment
- Problem with ajax request and directory structure after site migration
- My function echos only “array”
- Notify admin (by email) if post added with specific tag
- Retrieving specific images from Media Library
- Can’t put a hyperlink on Featured Post’s Image
- WordPress HTML Helper
- List sibling pages widget, exclude current page
- Send foreach $_post method to contact form 7 [closed]
- Remove Woocommerce product from cart with ajax/fetch
- Automatically change insurance quantity based on cart total [closed]
- How to pass value to add_filter wpcf7_form_tag from another function?