“hi” message is displayed instead of “hello” in the second example
Yes, because that’s how it works: query_vars is a hook for registering custom query vars that are public, so if the URL query string contains the custom query var, then WordPress will set the query var to the value parsed from the query string.
the desired situation is generally “hello”
You can override the query var via the request hook. E.g.
add_filter( 'request', function ( $query_vars ) {
if ( isset( $query_vars['myparamname'] ) ) {
$query_vars['myparamname'] = 'hello';
}
return $query_vars;
} );
Just be sure to use a unique query var or be cautious that you don’t override query var that shouldn’t be overridden.
Related Posts:
- Query multiple custom post types in single loop
- Inject post (from specific category) between posts in Loop
- Build a content and excerpt grid loop with paging and options for # of posts
- Using Cookie Data For WP_Query Loop
- wp_delete_post deletes all posts instead of just expired ones
- Alter secondary loop to exclude posts from current page category
- add_rewrite_rule with bottom priority doesn’t handle the WordPress pages
- Trim first 2 words of the exceprt
- Count number of published posts by type
- Display Post co-authored in Author Page
- Sorting Posts | Alphabetical Order
- Looking for most performant way to execute several similar WP queries within shortcodes
- Get the last month with posts using a recursive function…
- How to do multiple searches (with logical OR) in WP_Query in hook pre_get_posts?
- How to query for pages/post depending on slug?
- WordPress custom slug (endpoint) and compare all links
- wp_query with cat not working
- How to use an associative array in post__in with WP_Query?
- Recent Posts slider, using WP_Query(), loads duplicate sliders
- Compare post-IDs within WP_Query? (Less than / Greater than)
- How to use $query->set with post__in?
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- Display a specific category of products in shop page and disable code for specific actions
- Append query string to all URL’s
- custom rewrite rule help! Custom rewrite rules not applying to custom post type
- WordPress, AJAX and pre_get_posts using conditional tags
- get_posts() and WP_query limits ‘AND’ conditions to a maximum of 6 for meta value queries in WordPress
- Exclude posts based on meta value
- Custom query, checking values of multiple meta keys
- Remove echo from shortcode
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- Create a Blog Template Page
- Exclude posts with specific metadata from search?
- Display an image if odd number of posts in grid
- Why doesn’t PhotoSmash plugin play well with wp_query?
- WP_Query: getting posts where custom field exists
- How to show meta value code HTML after x paragraph
- Form search query – displaying ACF “Post Object” field as results
- get_the_ID() doesnt work
- Custom route and query
- change the default order of posts only for specific categories
- Getting posts to exclude from array
- Custom post type permalinks do not appear using the link functions
- Order BY Most Liked And Published Between Previous Week Monday And Next Week Monday
- How can I split my query result in 2 arrays?
- array_rand not working correctly?
- WP_Query() load selected post
- How to get post category list as select in front-end?
- Order a WP_Query by meta value where the value is an array
- How do I check if there is a tag in the title
- How to extract information from a wp_query result?
- WordPress Rewrite Rule
- Using multiple variables to assign categories to an array
- Search.php gets metadata from first post
- the_post(); prints out style text into my HTML?
- orderby meta_value_num is not working, giving default order
- How can I modify this code to make the search box include tags and meta
- Free search and custom taxonomy query not providing the same result
- WP_Query for woocommerce products with a pattern as a post_title
- WordPress Search Ajax + Isotope + InfiniteScroll
- How do I make these combination select filters work when only one dropdown is set? They work in WordPress 5.8.2 but don’t in 5.8.3
- How to call my PHP function with AJAX ? wp_query
- Ajax filter with loadmore button
- Query by pagename not Working
- Display featured image of post type category
- Delete post meta by serialized meta value
- can I extend the WP_Query class to deal with ‘duplicate’ posts created by joining to wp_posts?
- get_filtered_term_product_counts – Get product terms if any products
- Getting info about selected posts using one WP_Query
- WP_Query To Display Product Of Brand On Taxonomy Page
- How to display last whole post on the homepage
- How to return count of items found in SQL query
- wp_query beginner
- For each 3 posts, show a different post type
- Rewrite /keyword1+keyword2.html to search page | .htaccess
- WooCommerce – Print Processing orders [closed]
- Weird Behaviour: Not all WordPress Posts appearing
- List of child pages fetch next results at link click
- Query category-specific, paginated posts and allow viewer to change sort order
- wordpress is_main_query() breaks
- allow previews outside wordpress folder (Outsourcing WP previews)
- How to get category pages to look like a certain archive page?
- how to exclude admin page from add_rewrite_rule in wordpress
- Post Title Not showing up
- Advanced Taxonomy query, with 3 post types
- reorder a WP_Query, using a dropdown
- Custom query_posts() parameter
- Why does a meta_query break this WP_Query?
- How to modify this function to exclude also the post belonging to a specific category?
- Display biography post for today’s birthday person
- WordPress add parameters with friendly url structure
- How do I run the following script from my articles page?
- Execute multiple PHP Snippets causes error?
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- Three different queries on same page
- How to sort search result by post_title, then by post_content
- How to get posts by a certain author in inner loop using outer loop variable or post title WordPress
- Same Custom Post Type Slug and Custom Taxonomy Slug, with hierarchial unique permalink structure
- Show post in elementor based on views and specific category with query id feature in elementor
- How do I use fields => ids in an array with WP Query?