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
- Can wp_query return posts meta in a single request?
- Broken? WP_Query and “attachment” as a post type
- How to use the_posts_navigation for wp_query and get_posts?
- Order by DESC, ASC in custom WP_Query
- Exclude or Include category ids in WP_Query
- Secondary Sort (fallback) for WP_Query
- Changing the meta_query of the main query based on custom query_vars and using pre_get_posts
- How to paginate attachments in a secondary query as gallery?
- How to stop wordpress to make the default query?
- How to make an activities stream mixing posts and comments?
- WP_Query based on URL parameters
- Order by meta_value_num DESC and meta_value ASC on WP 4.0
- Order posts ascending with number in title
- How can I style future post?
- using wp_query to return posts w/ comment count > 0
- Order by meta_key in custom post type doesn’t affect the query
- Is there a PHP function that can match anything after the given URL, so my IF statement will work in each instance?
- How to hide post content/meta from everyone except the post author and admin
- Add a default meta_value to new posts
- WP query exclude post within the last month / only show over 1 month old
- WordPress query for most recent posts from multiple categories
- Too many posts cause slow load when paginating
- Order Posts by meta value AND published date
- Pass array of taxonomy terms to wp_query
- Formulate a url to show posts with both taxonomy terms
- How to reduce the number of queries?
- WordPress Related Post by tags in Single.php
- List of the years with posts presented
- Return Taxonomy/Term Information with Posts (WP_Query/get_posts)
- Query custom post type by custom taxonomy (category slug)
- Advanced Taxonomy Queries WordPress
- Getting post revision and printing them on the post content site
- Editing the default wordpress search
- Slow page loads due to WordPress Core Query
- wp_query for multiple cities (multiple values in a metabox)
- Adding column to wp_posts table or join wp_posts table with another table
- get posts by meta_key from inside key of post meta
- Help optimizing slow WP_Query with meta_query
- How to retrieve the date on which a post was moved to trash?
- wp_query with parameters
- Query posts with “non set” meta value
- Add filter post_where and passing post_type argument
- WP_Query infinite Loop
- Limiting number of related posts
- Ordering a mysql style datetime stamp with meta_query
- Advanced WP Query and/or
- 2 wordpress loops showing 1 post from same post type – how to avoid showing the same post?
- WP Query – order posts by meta field first and then order the rest
- Reusing content from front page on sub page
- Get Child Page IDs by Parent ID
- Wildcard search in WP Query
- Pagination works in custom query loop but it doesn’t work in shortcode
- Especific order by Custom Field Values in WP_Query
- Create a notification for post field
- Querying a large number of posts including their custom fields data
- Group posts by attachment meta key
- date_query is showing duplicate results
- How to query posts for custom post type with featured image for first 2 post?
- Why is get_the_excerpt returning full content
- How to avoid filling up an array each time I run a WP_query?
- How to SQL query posts IDs by categories AND authors?
- Randomly pick one testimonial post
- Display posts from an array of ID’s
- Date not appearing in custom query
- Custom post type – filter content by custom meta box content
- Trying to output content from page, works locally but not online
- Admin: Custom Query Returning Permissions Error
- wp query remove posts from query then update max pages and posts found
- Combine relationship posts with existing wp_query
- WP_Query Regexp whitespace and end of string
- Custom order of posts in wp_query and different taxonomies
- Slick slider for post doesn’t display anything
- What is the equivalent WP_Query of a SQL Query?
- Update wp_query every week
- Count post meta entries
- use mysql variable in a $wpdb->query to reindex a column?
- wp_insert_post with ACF Fields and WP Meta Query returns no rows until update
- Query WP Posts, then list the taxonomies from those posts
- Query post with content only
- Search with WP_Query, but ignore href URLs in anchor tags?
- Displaying Pages in Nav Sub-Menu with Specific Taxonomy Terms?
- Is meta_key used for ordering, filtering, or both?
- compare for multiple meta values for same key in wp_query
- Convert SQL Query to WP_Query
- Taxonomy Terms That Don’t Exist Display Results
- Why is my query not giving results?
- What argument does my function need to echo get_results() query results
- Using custom field as ‘orderby’ value causing post grouping by publish date
- Add pagination to table generated by wp_query
- Adding a Theme Customizer Control for Posts_Per_Page
- using next-page and previous page inside a wp_query
- Custom query from all posts & all child page from one parent page?
- What is wrong with this pagination code?
- wp_query conditionally get posts
- restrict posts per page
- the_excerpt() not working in custom archive
- Sort by multiple columns using get_posts
- WP_Query filter Posts by timestamp event (range start and end) and by month (next 12 month)