As @Pieter Goosen said, you shouldn’t be using query_posts
, nor running your own query. Instead, override the main query that already runs:
function wpse_144974_pre_get_posts( $wp_query ) {
if ( ! is_admin() && $wp_query->is_main_query() && is_home() )
$wp_query->set( 'cat', 1 );
}
add_action( 'pre_get_posts', 'wpse_144974_pre_get_posts' );
Related Posts:
- Can’t pass table to $wpdb->prepare
- Multiple Category Query
- Waypoints + infinite scroll with custom query
- Query String for the WP_QUERY parameters
- How can I create a meta_query with an array as meta_field?
- Query multiple meta key values?
- How to get comments by post ID?
- Is there a way of increasing the speed of this query?
- How can I query all users who registered today?
- Reversing the order of posts AFTER the query is performed
- what are the numbers between curly brackets in search query
- When/why does ‘$query->get( ‘tax_query’ );’ return empty?
- How to get link and title of next and previous post on single page
- Search custom post type by meta data
- Multipart/formatted MySQL query problem
- Remove [gallery] shortcode altogether
- query multiple taxonomy and show post count
- Categories and products in random order
- add_query_arg() XSS Vulnerability
- Query set using tax_query with relation ‘OR’ modifies category object?
- Filter query posts by the count of metas for a meta key
- Jetpack infinite scroll render – make different depending on post type?
- Isotope with Infinite Scroll
- Query posts by content lenght
- $wpdb doesn’t appear to work on page inside of a plugin
- Change searched term
- Query Posts By Post Publish Date, but sort by Custom Meta Key
- MySQL variable in query
- Search query -> Show all pages except certain template
- How to execute a SQL-query which contains multiple queries using $wpdb->query?
- Only show upcoming event or current events
- Why a URL with a query is always slower than that without a query?
- Maintaining Queries in URL
- How do I see the mysql query generated by get_posts( $args )?
- How to orderby multiple meta fields with another meta query
- Changing sort order for presentation by Jetpack infinite scroll
- Query posts using meta_key
- Modify users.php query with multiple taxonomies
- MySql Query very slow
- wpdb query problem to access previous 3 days posts
- Redirect to another page using contact form 7? [closed]
- How to change the amount of posts previewed on a page?
- Problem when try to add ++1 for user meta
- query statement containing variable won’t execute
- How to get events using multiple custom meta fields?
- Get posts from category with custom query
- Remove Jetpack infinite-wrap
- Slow Search Queries – How to exclude pages, media, excerpt, authors, private posts?
- Random Page Rewrite
- How to pull posts into two columns with different image sizes using $counter variable?
- WP_User_Query with more than two custom meta values
- Select column name dynamically mySQL Query
- how do i register global query in template
- WordPress Mysql query and Duplicate
- Combining two meta_values within one row with query
- How to “orderby” the first array in a meta_query that uses multiply keys?
- Sort query_terms_list for post_tags alphabetically
- Target a page with query
- List only parent attributes on woocommerce admin atrributes page
- How do I get specific readable results from this query and array results
- I want to get on those users their meta value are like “AGENT” .. but this query is not working
- Order posts ascending from posts in array
- Display data from phpMyAdmin with WordPress
- Add rewrite rule for archive search
- custom sorting media with multiple filters – error: not unique table/alias: wp_postmeta
- How can I get posts by 2 meta keys, prioritising one of them?
- SQL query to list all posts of specific post type with a specific set of associated postmeta values as a column
- implementing my wp_query using $wpdb class
- Category_in return empty
- Infinite scroll function for Twenty Seventeen
- Are there any best practices for creating a Like/Favourite feature in WordPress using custom MySQL tables and without any plugins?
- Query reversed when I use “category__not_in”
- modifying main query to query for ranges e.g. from 1999 to 2016
- How to reduce the load / no of queries on MySql Database
- Jetpack Infinite Scroll Not Working
- $query->set( ‘post_type’, ‘post’ ); not working
- How i make a custom sql query for Woocommerce
- Querying users by meta value and getting a strange answer
- Display result from custom post meta query
- Show certain number of post from tags
- Display Upload Author & Get Uploaded Post ID
- Display list of most recent grandchild (third tier) pages
- How can I display a number to represent the order of post?
- Problem on wpdb queries, wp_insert_post, wp_insert_user etc. The query runs twice
- Update vs Insert logic but the last key is always inserted?
- Sort order in get_posts [closed]
- Query unique author ids with published post of type job
- Sort loop with query in the link
- About WP’s save_post action
- $wpdb: how to use a query as a base for another query?
- Wpdb generates too many queries
- Multilingual WordPress page – using URL to determine language?
- Custom Query for searching through custom fields
- list or get meta_key where meta_value is ‘something’
- Query posts alphabetically within this function
- WP_Query with checkbox meta_query – WordPress [duplicate]
- How to display search query as formatted text?
- Custom Query for wp_posts using wp_postmeta
- WP Query outputs three items within a div
- How to figure out correct wp_options to have autoload=’yes’