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:
- How to display categories of my Custom Post Type?
- How do I programmatically add items of content to a custom post type?
- How to get a list of term names of the custom post type im currently on in single.php
- Ajax filter with custom taxonomies
- List events by month
- Custom post type loops with different page templates
- How can I programmatically save data into custom fields that contain serialized data?
- Adding a span when custom post type is updated
- Row actions not showing? Why?
- How do you output custom code between posts in the loop?
- Show ACF field from custom taxonomy and display on the single template
- How to make in WordPress admin panel sortable column for the custom field, that count the number of page impressions?
- Output custom post shortcode. Help spot the error.
- Blog page showing same content as homepage
- Custom Post Type Taxonomies -Posts not showing in Category or Tag pages
- A good strategy to print custom posts (offer) that are checked inside the metabox of a post?
- Can’t get order_by meta_value_num to work properly
- Create custom post type on successful woocommerce order [closed]
- Very Slow Page – How to Optimize # of Queries?
- Custom post type permalink returns bad url
- How to display selected taxonomies by their parent
- Custom Field Order by Last Name and First Name
- How to make sure content doesn’t display if selection is empty
- get the custom post type title/name
- Push metadata in array
- Get custom post type list for every category shortcode
- How do i calculate the total of values of custom fields in custom post types?
- Custom post type – get_day_link()
- I’d like to cycle through existing posts in a post type, showing one per day ordered by title, and starting over when the last is reached
- 404 error when navigating to a taxonomy page with Cyrillic, what’s wrong?
- Use custom metabox to update automatically a post after a given date
- get_post_meta not working on publishing
- WordPress custom post type split into pages
- Assign External Database Queries to Global Variables and Make Them Accessible
- Different Category system needed for the Custom Post Type
- Trying to get custom post of a custom taxonomy
- Loop increase number
- Is This Code Efficient – Or is there a better way?
- Get data from PHP to JavaScript to set position of each post on front page
- Removing full title and breadcrumb header container for a specific post type
- Filter content in shortcode
- Query custom post types & Taxonomies and list them in a table on a page
- Custom post type and custom taxonomy 404 on page 2
- Creating a “glossary” of WordPress posts of a specific post type
- Show current user posts in custom post type query
- Using Pagination for Custom Post Type and keeps returning 404
- Nested Custom Taxonomies | Incorrect posts when querying
- Validate Custom Post Type fields
- meta query not retrieving posts
- How do I get the index for a custom post?
- Commas not displaying in implode
- add custom tags for custom post type in wordpress
- CPT Repeatable Fields + Undefined Index
- foreach loop inside the loop creating duplicates in output
- Sets post_parent in custom post type posts automatically based on cpt->page name
- Show the categories the current post has
- Custom Post Type Causes Error: Warning: call_user_func_array()
- Front end create custom post types
- Is it a connection or relationship between 2 custom post types?
- redirect after submiting post for review
- How to display “Trash” in my custom post type?
- Custom front-end form for adding post – Category problem
- set object terms after some some time of published post – functions.php
- Why is my custom post content only viewable when signed into WordPress?
- Get only parent post in archive post
- update custom taxonomy custom fields
- Filter taxonomy by CPT
- Query custom post type that has a serialized relational advanced custom field value
- Pagination not working in custom post type. Help
- Sending current featured image to email
- Plugin Development using classes – Public & Private Callbacks
- Dynamic page for nav items used as filters
- How to use posts as tabs in a custom page?
- ACF field check value of field on all other articles
- How to use POST method using custom wordpress button?
- Get meta values from parent post and save in child post
- News post with multiple permalinks? When opened from different page
- Custom post pagination not working
- WordPress trying to query two custom types to get child from the parent
- Wrap each child and it’s grandchildren separately
- Duplicate posts in my custom loop
- Include images from pages in wp search.php results in default wp search
- WordPress loop add heading before first of type
- get_post_meta for Custom Post Type ( CPT )
- How to display all custom fields associated with a post type – IN THE ADMIN AREA?
- Meta box not saving
- Featured image in custom post is being disabled
- Why isn’t my custom post type using the corresponding custom post template?
- Custom Search not working
- Order by custom field attribute
- Custom Post-type not returning the right child_of
- Custom Post Types and 404 Pages
- Cant we use a PHP file directly like myhome.com/some.php?
- Code in custom widget queries all posts, when it should only query the current post
- WordPress Set A Static Page/Template For All Sub-Pages
- Add HTML before a specific div?
- Is there any way of not using my_init_method in the following code (that creates a custom post type)?
- Display ONLY ONE $term (Out of 4 terms) from a Custom Taxonomy and CPT
- Add Category names to post lists of custom post type
- how to display custom taxonomies in front page