Sessions aren’t enabled in wordpress by default, if you want to activate php sessions add this at the beginning of your functions.php
:
if (!session_id()) {
session_start();
}
You now can use $_SESSION['your-var'] = 'your-value';
to set a session variable. Take a look at the PHP documentation on sessions.
Update:
There was a second answer, which, in my mind, had a value too – unfortunately it got deleted, I’m re-adding the information here. The answer was referring to WP Session Manager a plugin written by @eamann as a alternative solution.
I read some things about the plugin, but never used it because – so far – I’m sticking with PHP sessions – never had the problem that I couldn’t use them. This is a statement/comment by the plugin author himself I found about some possible advantages.
Related Posts:
- How to store and receive variables in WP sessions?
- Display if author page is author page of current user
- Use REGEXP in WP_Query meta_query key
- Why is the loop not empty on some 404s?
- Pagination on a WP_query not showing navigation links
- Multiple custom fields for ‘orderby’ in ‘WP_Query’
- How to order by post_status?
- switch_to_blog() performance considerations & alternatives
- What’s the best approach for showing posts by A->Z order?
- Load more AJAX on WP Query
- Paginated pages are showing correct content but pagination links are not
- Query Posts but only return 1 from a custom taxonomy?
- Loop inside the loop
- WordPress search exact match
- How to count post type that has a particular term?
- Group posts by meta_key
- How can I hide posts that are over 2 years old
- WordPress custom search form with pre_get_posts not work
- wp_query, give first post different formatting
- WordPress: Keep order of query_posts list of post ID’s using post__in
- Best practice custom function, where to echo the variables?
- How to get user_id from wordpress database inside ajax function?
- meta_query works locally but not on live server
- getting posts and number by specific meta value in multiple meta
- Retrieving list of a custom post type in a widget without using WP_Query?
- How to orderby meta_value_num with dollar ($) sign
- Order WP_Query by multiple fields, subtracting them from one another
- How can I convert results of WP_Query (of Custom Post Type, with Custom Fields) to JavaScript?
- Query with custom taxonomy not working
- How to order posts in wp_query by the user role (2 roles in array)
- Reset postdata to custom query in nested queries
- How to change main query based on post meta
- add active class based on permalink and url
- Loop Split two Columns
- Search by post id in a specific page then auto-redirect to searched post
- Pretty urls for custom pagination
- WP_Query with ‘rand’, but equal number of posts from the taxonomy terms given
- Add posts to WP Query object
- use of 10 new WP_Query : loading too slow (with url) [closed]
- How to make a second query offset -2 from current post
- How to not display tags with less than X posts
- Order or Orderby in tax_query (How to define order of terms in WP_Query)
- Wp_query with 2 meta keys and array of meta values
- meta_query: check if number exists
- Search Page Returns Nothing
- Create a loop on my pages with new “WP_Query”
- Which meta_query and post_content blend is better in WP_Query, performance wise?
- WP Query causing timeout
- WP ForLoop to compare meta information of posts to determine what post to display
- Problem with get_page_by_path() using with WP_Query
- Query where ANDing slug values not working
- Woo Commerce using WP_Query to get products that match price range, with an additional required product attribute
- Multiple wp_query on archive page
- change posts_orderby of the callback wp_query?
- Retrieve select tag custom values from array and display them in current page with wp_query?
- How to use a dropdown to filter posts by custom field
- Content not displaying on paginated page
- WP_query is not returning the expected result
- show custom category posts from a custom post type
- how to load posts to a custom post template after using template_redirect or template_include
- 2 queries with counters
- wp query meta value is not null
- Trying to use WP_Query to display a custom post type
- WP Query / Meta Query [duplicate]
- Page template doesn’t display simple HTML if inserted into other page?
- Query multiple post types, but different order for each
- How to add date_query to meta_query array
- Order by the first array within a meta_query
- View list of custom posts within a date range relative to today’s date, based on a custom date field
- Multiple nested meta queries
- order by post date and modified date posts both in wpquery
- Comparing Meta Field date in WPQuery using Meta_Query?
- Fix wp_term_relationships slow query in get_posts
- Custom query for custom post type not getting correct post ID
- How to merge these two post queries?
- How to search posts by title with special characters in WP_Query?
- Query postmeta based on meta_value, return array of post_id
- WP_Query: Query posts only if their access is restricted to logged user’s role
- datetime picker, timestamps and meta queries
- Get specific value from variable to use in query
- WP_Query with meta_query won’t orderby
- Adding Category in WP_Query Not Working
- Meta key in wp_query bug?
- display all posts from category with and without terms in chronological order
- How can I create another instance of my custom shortcode
- How To Call WP_Query From A Subdomain?
- Extending WP Query: Custom geolocation meta values work, but tax_query breaks
- WordPress: Cron locking and Queue
- Correct Way To Run Multiple Queries Sharing Some Base Data
- how to query for meta_value have array
- How to make the default WordPress search return borader results
- Show sticky post before other WP_Query
- List ALL posts within last week from current category on category page
- WP_Query on “property” in the options table
- Post OrderBy slow performance
- Dynamically name array in WordPress loop – add/get values
- Showing posts from 4 categories along with all latest posts
- Searching in specific custom post type
- Hook to get the query result after listing posts
- Display only posts with thumbnails