“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:
- WP_Query | Help me create a search term with an ‘OR’ relation?
- Why does “get_option” pull in the older value in options.php, rather than the newer value, on submission of a form?
- WP_Query use for a filter with multiple Taxonomies and Terms
- Duplicates with WP_Query loop
- Newbie question: no index.php? in my plain wordpress permalink
- Display related products with custom output
- How do I dynamically generate args for wp_query?
- Sorting Posts | Alphabetical Order
- Looking for most performant way to execute several similar WP queries within shortcodes
- Use wp_get_recent_posts with search term
- have_posts() execution failure
- Can’t search posts using WP_QUERY inside AJAX Function
- How can I use wp_query to show all product data using just the products ID?
- Get Current User Id Inside a Loop Returns 0 For a Shortcode
- Custom page archive query by url var calling page twice on one of my custom queries?
- How to query for posts with a null or blank post_name?
- WordPress pagination not working with search page
- WP Query with custom Shortcode
- Advanced Meta Query for Large Calendar Website (12k+ posts) (175k+ wp_postmeta rows)
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- Changes in permalink structure in WordPress and how to apply to in-site links
- Add more button if more 8 items
- How to store post ID’s in cookie or session to display the same posts later
- custom url rewrite for wordpress
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- auto-populating custom nav with all items from custom post type
- WordPress theme options error
- Get posts from multiple post type
- WP_Query fails despite having 1 post
- wp_query get the 2nd post
- How to add div blocks after certain set of post
- the_posts_pagination() not working in wpquery
- WP_Query | IF within $args array | Help me only add specific arguments if the argument is not blank
- Convert a string into a decimal number for use in query
- Increment paged on WP_Query
- Hide posts if user is added to it WP_query
- Get all posts as an array ID => Name
- How to hide posts of a specific custom category in WordPress?
- How to insert wp_users ->user login name to wp_terms when a new user registering?
- Passing an array into WP_Query as a variable
- Custom query vars filters problem with pagination
- Order BY Most Liked And Published Between Previous Week Monday And Next Week Monday
- Modify main query before it run without pre_get_post
- WordPress WP_Query without query GET parameters
- Sort posts in a specific way
- Do not duplicate posts with multiple categories in multiple loops
- posts_nav_link pulling in multiple post types
- Displaying Event within two given time frames
- Remove Post if Advanced Custom Field is checked to fix paging
- displaying a fall back query if there’s nothing in the post-type category
- Modifying WP URL handing code?
- Search AJAX Filters – Multiple Query Loops Into One Loop (Optimization)
- WP_Query: How to get results from both meta_key options?
- Free search and custom taxonomy query not providing the same result
- How do I reset $wp_query in a function?
- Change permalink structure specific category
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- wp_query with multiple arguments with AND
- Passing in MySQL prepare statement parameter separately throwing error
- Replace a single variable with add_filter
- Nested Queries of decreasing specificity
- 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
- Load more posts using AJAX based on posts inside WP_Query
- in_array not working on dev server but works on localhost
- meta_query search names when they have middle initials
- WP query posts BUT show the most recent and one per author
- Define global custom post
- How to select post ID for given parent name with nested prepared queries?
- get_filtered_term_product_counts – Get product terms if any products
- Rewrite rule for wp
- Add code to the header of posts by particular author
- Search for single post by 2 tags
- List all ACF field values across every post on one page
- Multiple Arrays for Custom Post Query using Boostrap accordions and ACF repeater fields
- Query to show average # of months all accounts with specific role have been active
- Woocommerce Related Product by 2 taxonomy
- Help on Wp_query to print an term
- Query doesn’t display text data with apostrophes
- Querying posts from wordpress with 2 or more conditionals
- SQL Query Search page
- Can’t get data from audio media
- Display Year and Month from custom field + Age Calculator
- insert thumbnail image from php script
- WP_Query count of different meta key values [duplicate]
- add_rewrite_rule questions
- Masonry layout within the loop
- rewrite_rule – working fine but broken for pagination
- Pagination in category.php not functioning
- Fix incorrect related posts code snippet
- wp_query on search results page showing all results every time
- Changing regular db connection to $wpdb
- Variable ++ in query loop
- XML WP_Query problem in PHP 8.0 and 8.1
- a problem in class in class-wp-hook.php
- Count custom posts type and filter by tag
- AJAX WP_Query’s order and orderby parameters not working
- How do I display WooCommerce products in my query to rows of 3?