I would avoid the use of query_posts — it forces another database hit. There are plenty of other ways to hook in and change the query before posts are fetches. pre_get_posts
is one of them.
To display multiple post types on the home page (pages and posts in this example):
<?php
add_action('pre_get_posts', 'wpse70606_pre_posts');
/**
* Change that query! No need to return anything $q is an object passed by
* reference {@link http://php.net/manual/en/language.oop5.references.php}.
*
* @param WP_Query $q The query object.
* @return void
*/
function wpse70606_pre_posts($q)
{
// bail if it's the admin, not the main query or isn't the (posts) page.
if(is_admin() || !$q->is_main_query() || !is_home())
return;
// whatever type(s) you want.
$q->set('post_type', array('post', 'page'));
}
This would go in your themes’s functions.php
file or in a plugin.
Related Posts:
- Inconsistent temporary 404s on whole install | PHP error with post-template.php
- Custom post status not working
- Search that will look in custom field, post title and post content
- Load custom posts with same tag as page
- Date archives for custom post type
- If featured image doesn’t exist, show post content
- How can I add dropdown widget/box to admin post page?
- Meta Query “IN” doesn’t work with ACF checkbox filter
- How do I redirect all 404 errors of a specific post type to another URL?
- Using ‘strtotime’ function to convert a custom-meta-box to a date-stamp
- How to save the checked boxes?
- How to get only one category of custom post type?
- Error after deleting Custom Post Type with a function (no trash used)
- Custom Post Type .current-menu-item not applying on Custom Post Type Archive Page
- How to allow “Add New” capability of CPT when links to its UI are placed as a submenu?
- wordpress custom post type remove duplicate menu item
- List terms from Custom Taxonomy
- WP_Query search posts by custom post type and custom taxonomy
- Dynamic Custom Post Type Plugin
- How to filter out post type meta?
- Loop through posts of a custom-post-type (event) and create .ics (iCal) file?
- How to count custom post types with conditional operators
- Link users to a custom post type
- Notice: Undefined index: suppress_filters
- Using wordpress template tags within an array
- How to display Custom Post Type Post based on Tag with Shortcode Parameter?
- Getting the URL of the parent page
- get_posts of Custom Post Type AND Custom Taxonomy
- Get posts from a custom post type by child categories of a parent category
- If post has custom field then display css-class
- Replace text in post from cvs
- Get parent categories of custom post type
- Custom post type is showing custom home page, not archive page
- Query & Order posts by custom fields
- Custom Tag Description unable to display just below and outside of the Loop
- Can one create multiple Custom Post Types with a for loop?
- How to Upload CSV Data into Custom Post Type Data with Metabox programmatically
- How to add custom field to view-edit post type page
- Static apple-app-site-association file with wordpress
- search suggest – filter post type
- Custom Post Type within the Loop on Homepage (Page Template)
- Breaking up CPT output into two columns
- How to update post meta on uploaded image from a custom form?
- Configuring a meta query with multiple post types that have the same relationship on a single page
- how to echo meta tag in header using php
- Trying to get custom post of a custom taxonomy
- PHP question: how to combine syntax?
- Add first letter of titles to array, then compare arrays
- How do I add custom HTML to the content of an archive page’s posts?
- widget_posts_args not using the number of posts in widget
- How To Post WordPress Custom Post Types to Twitter via IFTTT
- Undefined $post in wp_query
- Filter content in shortcode
- Custom post type and custom taxonomy 404 on page 2
- Show current user posts in custom post type query
- Importing JSON feed giving Notice: Array to string conversion error
- List latest post out of 2 custom post types
- Sets post_parent in custom post type posts automatically based on cpt->page name
- Show the categories the current post has
- Fetch data from two custom post types and create multidimensional array for output to html table
- Create a Dropdown Selector and Redirect for a Custom Taxonomy in WordPress?
- Create an user checklist system for a course plateform using ACF Pro and ACF Extended
- How to display “Trash” in my custom post type?
- How to get the custom post data using post id in WordPress?
- set object terms after some some time of published post – functions.php
- See if the email exists or not
- Why is my custom post content only viewable when signed into WordPress?
- On saving Post My permalink is updated and category is removed automatically which cause the 404
- Pagination not working in custom post type. Help
- How to add specific terms in a custom post type?
- Sending current featured image to email
- Plugin Development using classes – Public & Private Callbacks
- Limit custom post type to the authors only on front-end!
- WP_Query – How To Query Only Custom Posts With No Children of Their Own?
- programmatically generated custom post type is created more than once
- Dynamic page for nav items used as filters
- How to use posts as tabs in a custom page?
- Accessing download link from the loop with WP Download Manager Pro
- Create posts inside CPT post
- ACF field check value of field on all other articles
- Taxonomies are not showing in the category dropdown
- How to use POST method using custom wordpress button?
- Combine multiple separate lists into one
- News post with multiple permalinks? When opened from different page
- Custom Taxonomy – fields
- WordPress trying to query two custom types to get child from the parent
- Print post category name from a custom post type wordpress
- CPT post doesnt shows tags and category on backend admin page
- How to make sure, that only the selected post is changing?
- Create 2-layered dropdown menus for custom taxonomy and custom post type
- Get month and day from a Date Picker custom field
- Show Custom Post Type taxonomy term that matches custom field
- Order by custom field attribute
- Select Menu for Custom post Type does not save
- is_singular won’t call my functions?
- Cant we use a PHP file directly like myhome.com/some.php?
- Inserting two categories
- Comments are not working on Custom Post Type
- Add Category names to post lists of custom post type
- how to display custom taxonomies in front page