I have installed the Custom Post Type UI plugin. After activation of this plugin I have created a custom post type called portfolio
. Now I want to use this on the portfolio page in the front-end. How do I fetch all post that are of custom post type portfolio
?
Leave a Reply
You must be logged in to post a comment.
which shows both normal posts and posts inside
portfolio
typeor
for only
portfolio
.Use as normal WP Query – read the Codex: http://codex.wordpress.org/Function_Reference/query_posts#Usage and http://codex.wordpress.org/Function_Reference/query_posts#Post_.26_Page_Parameters
Late answer as the main answer uses
query_posts()
, which should never be done.Use a filter
Use the
pre_get_posts
filter and just set theportfolio
post type for the main query. Use Conditional Tags to determine where you want to have this filter.Quick Example
Disclaimer
The above code is a plugin, but can simply get stuffed in the
functions.php
file of your theme (which is not recommended).Add this code to your child themes functions file (recommended) to add your single CPT pages to your main loop
Source http://codex.wordpress.org/Post_Types
Or create a custom archive-portfolio.php page template which will only display your CPT pages. This only needs to be done if you haven’t added a archive page using the plugin settings.
Example: ‘has_archive’ => true,
You can also control how many pages are displayed and the order in which they’re displayed on the archive page using this code: