In my test scenario I use the original twentytwentyone theme with no
plugins activated. My code is placed at the end of functions.php.
This is the problem. Your code is running as soon as functions.php is loaded, which is before the query vars are populated. If you use get_query_var()
inside an action hook that runs later, or inside a block or shortcode, it should work fine.
Related Posts:
- How to declare a global variable in php?
- Undefined variable in functions.php file [closed]
- Mega Menu Walker
- How to add a class to the attachment images
- Why would a GET variable one one page of a site cause a 404 error when a GET variable works on another page of a site?
- load/require specific php files for specific pages/templates/post types
- Activate different theme for temporary preview
- Execute a shortcode when clicking on a image
- get_the_content if it contains multiple lines it results in SyntaxError
- Store loop into array
- Add a custom text field to WooCommerce admin product data “Variations”
- Show Specific Footer Widget for Specific Pages
- How do I output a database option that is an array into a get_posts array?
- Why is it necessary to prevent direct access to included files?
- Run a Parallel PHP Application with WordPress
- Display Post co-authored in Author Page
- Include Class File in WordPress
- Change logo based on incoming domain
- How can I use a $wp_customize to edit my homepage image slider?
- Password protecting content in custom template
- Creating login session via CURL
- WordPress vs. Custom PHP [closed]
- How to Display a Single Post Excerpt
- Trouble With Conditional Logic in PHP
- How do I display a user’s previous orders as a select box option on a product?
- How to Highlight unread WordPress posts?
- ajax, right way to do it and make it works?
- Is there CSS to expand the gallery limit on Index Pages?
- Hide categories that are not used in the post type
- How to combine wordpress_logged_in cookies in one cookie?
- Is it possible to increase php memory without directives in wp-config.php, .htaccess or php.ini?
- Adding widgets to my plugin page instead of WordPress dashboard
- Limit 1 global comment per minute
- How can I add an area/option for a custom page description?
- Menu jumping when calling it via PHP
- Problem custom control Customizer
- Running code before object-cache.php runs
- How to escape attachment image caption text?
- WordPress admin is incredibly slow [closed]
- Is there a way to conditionally check whether a WordPress post title is empty?
- Use WordPress function in php file
- How to parse multiple links from one variable?
- Issue with php version 7.2 in running search
- How Can I Edit the Registration Code?
- What is the right way to add PHP code to a certain part of a page
- Can I make get_users() query global?
- Display attribute on shop page after the title
- Cant connect to database with php 7.3
- iframe not showing in content on blog page
- WordPress WP_Query without query GET parameters
- How to clone all WordPress Rest API end points
- Get the name of menu item with wp_nav_menu
- What’s wrong with this piece of code? [closed]
- Where to copy woocommerce files to in my custom theme to avoid editing the core plugin?
- Controlling image output size ACF repeater [closed]
- Initial offset of number of posts in home page on the posts page
- Run JS Code on userlog out
- Twentyfifteen style author comment
- I installed WordPress locally now how do I login?
- How to set base url for php widget
- Remove the Tag from wp_nav_menu
- How do I choose not to display the title header on a specific page?
- Time Delay a URL Redirect for Specific Page
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- Sort column in Users admin Tab
- jquery & ajax getting data from php in wordpress . admin-ajax.php returns 400
- Is it possible to order posts using multiple meta queries, i.e. show posts from first meta query, then the second?
- File from parent theme imported to child theme doesn’t work – any ideas?
- I can’t go to the page archive-{post_type}.php
- Loading Widgets Via Child Theme
- use php variable in wordpress page
- (solved) WordPress Site not loading properly
- Class ‘WP_Privacy_Requests_Table’ not found
- Use Search Term in html link and redirect
- AJAX numerical pagination problem in TwentyFifteen-child theme
- Access WP files on “server 1”, from “server 2” – using wp-load on an external website
- How to change query string with pretty URL in WordPress using .htaccess file
- I want different post-thumbnail size depending on media size
- Popular Post Not Show
- Submitting my form to the database and then redirecting to payment site
- Remove all nav menu classes except those which begin with certain letters
- ACF loop and php formatting
- .htaccess on multisite and roots theme?
- how to set category name for a post
- Move wordpress sidebar on homepage up to new position
- What’s the most efficient way to write multiple WP_Queries on a page?
- How to get shared CSS body class between translated WPML pages [closed]
- Can’t get options with $data[‘variable’]
- foreach all the post
- Custom archives page by month and year – nesting problem
- Blog Posts not sorted and pagination not adjusted after filtering some category
- Need help with Deprecated: Non-static error when update PHP 7.4 -> 8.1 with Dyad 2 theme
- kali php problem [closed]
- Why is my array_diff usage breaking things?
- Why is this specific API request failing when sending via wp_remote_post?
- Can’t send form data to wpdb when URL has query string
- Need help with conditional logic for menus
- Disabling User Email Notifications for Erase Personal Data Utility
- Facing Problem While Running WordPress Hook For Archive, Categories, Author, Date Pages Only
- generate excerpt from the part of big text dump that contains keyword