get_query_var()
gets variables from the main instance of WP_Query
. It’s the equivalent of running
global $wp_query;
$wp_query->get( 'posts_per_page' );
It is not directly related to $_GET
in any way. However, WordPress has a list of ‘public’ query variables that will be applied to the main query if they are passed as URL parameters. This is what the query_vars
is filtering. You can see the list here, as the $public_query_vars
property of the WP
class.
So when you run get_query_var('posts_per_page')
you are getting the posts_per_page
property of the main query. This will typically be the value from Settings > Reading. Passing ?posts_per_page=2
is not setting this value because posts_per_page
is not a public query variable.
Related Posts:
- WP_Query leaking absurd amounts of memory
- Fatal error: Class ‘ms\WP_Query’ not found on plugin initialization [closed]
- Register custom query args parameter for WP_Query()
- How to add multiple custom URL variables?
- Getting wrong relationship value in $args in wp_Query?
- Check for featured image in WP_Query
- Why Does get_posts() Return an Empty Set?
- How to get data from WordPress $wpdb into React Gutenberg Blocks Frontend?
- get_posts / WP_Query Memory size of 134217728 bytes exhausted
- How to ensure “the_content” filter runs only for the main displayed content?
- add_filter and remove_filter added before and after wp_query
- How to get all images and their thumbnails from wp media library
- How to create a dynamic page based on form data with a plugin?
- How to Display Custom Post Type’s Gallery (images ) in Through WP_Query
- Handling form request from plugin file
- Passing array of strings to a SQL statement in a WordPress plugin
- Cannot search post by taxonomy
- How to get orders with used coupon in WooCommerce
- WP_Query with tax_query, order by most ‘matches’
- How to print raw query from WP_Query class just like in CodeIgniter
- WP_Query returns no results
- Finding posts containing matching array elements in a meta field usign WP_Query
- Create a custom display order in the main menu
- manage_posts_custom_column, showing serial number using increment in loop
- Error : “Cannot use object of type WP_Post as array in”
- Proper way to run wp_query from inside a plugin
- using new WP_Query in save_post function alters $post
- Slow WP_query due to nested wp_query. Need Suggestions
- ORDER BY wp_post custom column name in wp_query
- get_query_var not works
- How to create database table, add data, update and delete using wpdb via plugins?
- Elementor custom Query with ACF fields to show matching woocommerce products custom fields
- WP_Query filters
- How to fetch only current hour posts?
- How to get Metabox custom field to show checked if value is updated using post meta query?
- WordPress pre_get_posts with combined results of two queries (OR)
- Search: how to extend the existing search to include a custom table
- how to get all the child category name in a specified category name?
- how to invoke wordpress API from other existing PHP system
- How I can use order by of the custom post title?
- How to query children by post name/slug
- 400 Bad Request, in wordpress theme development, wp_ajax
- Prevent WordPress automatically processing certain URL queries
- Store custom meta box data as serialized array
- how to load the comment template from a plugin
- How remove trashed WooCommerce orders from wc_get_orders() result?
- How to call code when adding WooCommerce menu items via woocommerce_account_menu_items
- Auto-complete or auto-suggest from stored data in database
- Get post thumbnail in WP_Query
- Pagination not working with custom wp_query
- Get Posts by IDs (optionally)
- Adjust query on single
- WP_Query order posts by category
- Is it possible to use the MySQL’s ORDER BY FIELD() clause as part of the pre_get_posts hook?
- Multiple dynamic Tax Query – pass taxonomy argument from array
- WP_Query not ordering correctly
- How to check category name available or not
- Home page is not loading, where in other pages are displaying on the site
- how to create a shortcode from a variable in plugin
- User meta query using Wildcard
- Group By in a Metaquery
- WP Query date_query with several date range
- Making Woocommerce optimized for more than 500k products
- Post Pagination does not working on WP-Query
- WP Query Relations / Compare
- pull data from wordpress database
- How can I query 3 posts from diferente categories (one of each category)
- Query only title/field/featured media of posts [closed]
- Custom MySQL query to pull out Advanced Custom Fields?
- post_results filter confused by pagination in sidebar and main section
- Can’t get query string in ajax call
- Get custom wp_query search results to appear on search.php
- loop and in admin header problem
- How do I query posts and have their related taxonomies returned in the results?
- Best Way to Inventory the Media Library of a 200+ Multisite Installation?
- What is the meta_query key name for the woo product average rating? [closed]
- get the queried_object of an url
- Return custom product in ajax call loop
- filter on get_posts efficiently
- Best practices for using the transients API
- Elementor Fatal error: Class ‘Elementor\Widget_Base’ not found
- Headers already sent error with CSV export plugin
- How to add HTML / Form to an Admin Bar Menu
- Is there any background process that I can run from plugin without depending on page hits on a website without affecting page-load speed?
- Woocommerce how to update variable product price programitically?
- Using $wpdb object in a widget
- Can I use the different settings sections over different pages using the save options group?
- WYSIWYG editor in WP 3.2 plugin
- What is minimum time interval for which a cron be scheduled?
- How to show filters on table when using WP_List_Table
- Add a default WP comment form to forum template
- Plugin: database creation
- How do I remove folder and contents I have created while installing plugin
- I have this error notice ‘wp_enqueue_script was called incorrectly’ in my plugin
- Questions about meta box: nonce and parameters available
- How to Login a User inside a Plugin and Redirect to page?
- WordPress function is not called and ajax return 0
- Method not receiving attributes from shortcode call, general OOP problems
- Is there a canonical way for a plugin to install a mu-plugin or drop-in?
- Calling get_header() with installed FSE theme