“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:
- Search AJAX Filters – Multiple Query Loops Into One Loop (Optimization)
- WP_Query: How to get results from both meta_key options?
- orderby meta_value_num is not working, giving default order
- Wp Query : Order by distance lat,lon
- 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
- How to WP_Query posts order by parent title?
- Prevent Buddypress Rewrite Rules on Non-Buddypress pages/posts
- How do I reset $wp_query in a function?
- search.php to search only the post title
- Let current user know pending posts counts using wp_query
- Output product category link from WP_Query
- Change permalink structure specific category
- WP_Query – How to query all of post types categories
- get_terms with specific id order
- How to work Woocommerce pagination inside shortcode?
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- WP_Query for woocommerce products with a pattern as a post_title
- “pre_get_posts” orderby custom date field in different format?
- wp_query with multiple arguments with AND
- 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
- Passing in MySQL prepare statement parameter separately throwing error
- Replace a single variable with add_filter
- Nested Queries of decreasing specificity
- get different meta-data of a complicated query at the same time
- Wrong pagination results, page counter resets when navigating
- Is it possible to order posts using multiple meta queries, i.e. show posts from first meta query, then the second?
- Sending simple variable on single page to WP JSON
- How to exclude meta no index pages from wp_list_pages
- Using a new WP_Query inside the loop
- wp_Query with mutuplea values returns all posts
- Load more posts using AJAX based on posts inside WP_Query
- in_array not working on dev server but works on localhost
- wp_query – Exclude the first thumbnail from lazy loading on archives
- meta_query search names when they have middle initials
- How to call my PHP function with AJAX ? wp_query
- WordPress sorting posts by date and title using a dropdown
- Custom search query on WordPress page not working
- WP query posts BUT show the most recent and one per author
- How to get specific multiple pages excerpts at homepage?
- Ajax filter with loadmore button
- Define global custom post
- How to select post ID for given parent name with nested prepared queries?
- posts_per_page displays only 2 posts instead of 4 posts
- Usermeta data unserialize, extract and display in table in WordPress
- Use WPQuery to match to specific repeater row in post
- Query by pagename not Working
- Custom query_posts() parameter
- WP_Query based on another query on the page
- Why does a meta_query break this WP_Query?
- Does wp_query and query_posts affect website performance? [duplicate]
- Keeping the previous get value and add another value when submitted
- WordPress post pagination on custom template not working
- Ajax Load More or View More functionality for woocommerce category layout by template overriding
- Pagination in category.php not functioning
- How to modify this function to exclude also the post belonging to a specific category?
- Fix incorrect related posts code snippet
- wp_query on search results page showing all results every time
- Show post like this image in my newssite [closed]
- Display biography post for today’s birthday person
- WordPress add parameters with friendly url structure
- WP query with variables gives no result for specific user
- Display all categories (with link) of custom post type – WordPress
- Changing regular db connection to $wpdb
- How do I run the following script from my articles page?
- Variable ++ in query loop
- Execute multiple PHP Snippets causes error?
- XML WP_Query problem in PHP 8.0 and 8.1
- a problem in class in class-wp-hook.php
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- Count custom posts type and filter by tag
- Three different queries on same page
- How to sort custom sortable column by custom table value
- /page/2/ redirect to 404
- How to use a conditional statement in a post loop but not count towards the “posts_per_page” if false
- AJAX WP_Query’s order and orderby parameters not working
- Add adjacent post function inside custom recent post function
- add_rewrite_rule image from /images/site2/favicon.ico to /favico.ico
- How to sort search result by post_title, then by post_content
- How do I exclude the current post from the upcoming post query
- How do I display WooCommerce products in my query to rows of 3?
- How to get posts by a certain author in inner loop using outer loop variable or post title WordPress
- wp_logout action hook is not firing
- How to show correct td of table tags in wp_query loop
- Exclude first post from wp query
- 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
- Check for a value in a custom query
- How to make posts_like_dislike reference current post when iterating?
- AND and OR in my CPT search query depending on checkbox
- Add css class ID to largest and smallest number a custom field in wp_query
- External WP_Query call from PHP crashed after version update
- How to Dynamically Change the author_base URL Slug by Language in WordPress?
- How could I prevent using the same custom loop in a template file when I only need to change one meta_query parameter?
- Add up all numbers from a WordPress query [closed]
- Developing a “fallback” for empty wp_query results based on post dates
- Display posts in correct month order using single date custom field
- How can I save the HTML output of a WP_Query function as a variable?
- WordPress query_posts with multiple tax_query