Related
I have a custom post type called 'location' where the top level is state, second level down is city, and the third level is the actual location.
I've used the methods recommended here and here with no luck. I've tried get_pages(), get_posts(), get_children() and it's either retrieving all children or retrieving all pages.
Here is my current code that is in the single template of the custom post type:
<?php $args = array(
'child_of' => $post->ID,
'parent ' => $post->ID,
'hierarchical' => 0,
'sort_column' => 'menu_order',
'sort_order' => 'asc',
);
$locations = get_pages($args); ?>
<?php
foreach ($locations as $location):
$title = get_the_title($location->ID);
$locale = get_field('location',$location->ID);
$lat = $locale['lat'];
$lng = $locale['lng'];
$addy = $locale['address'];
$hours = get_field('hours',$location->ID);
$link = get_the_permalink($location->ID);
?>
<div class="location-single" data-lat="<?php echo $lat; ?>" data-lng="<?php echo $lng; ?>">
<?php echo $title; ?>
<address><?php echo $addy; ?></address>
<time><?php echo $hours; ?></time>
</div>
<?php endforeach; ?>
EDIT: To cover all my bases, here is the code i'm using to register this custom post type.
function custom_post_type() {
$labels = array(
'name' => _x( 'Locations', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Location', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Locations', 'text_domain' ),
'name_admin_bar' => __( 'Location', 'text_domain' ),
'archives' => __( 'Locations Archives', 'text_domain' ),
'attributes' => __( 'Location Attributes', 'text_domain' ),
'parent_item_colon' => __( 'Parent Location:', 'text_domain' ),
'all_items' => __( 'All Location', 'text_domain' ),
'add_new_item' => __( 'Add New Location', 'text_domain' ),
'add_new' => __( 'Add New', 'text_domain' ),
'new_item' => __( 'New Location', 'text_domain' ),
'edit_item' => __( 'Edit Item', 'text_domain' ),
'update_item' => __( 'Update Item', 'text_domain' ),
'view_item' => __( 'View Item', 'text_domain' ),
'view_items' => __( 'View Items', 'text_domain' ),
'search_items' => __( 'Search Item', 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ),
'featured_image' => __( 'Featured Image', 'text_domain' ),
'set_featured_image' => __( 'Set featured image', 'text_domain' ),
'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
'use_featured_image' => __( 'Use as featured image', 'text_domain' ),
'insert_into_item' => __( 'Insert into item', 'text_domain' ),
'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ),
'items_list' => __( 'Items list', 'text_domain' ),
'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
'filter_items_list' => __( 'Filter items list', 'text_domain' ),
);
$args = array(
'label' => __( 'Location', 'text_domain' ),
'description' => __( 'Locations', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor','page-attributes' ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_icon' => 'dashicons-location',
'menu_position' => 8,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'location', $args );
}
add_action( 'init', 'custom_post_type', 0 );
I'm inserting this into the the_content area using this:
add_filter('the_content', 'location_content');
function location_content( $content ) {
if ( is_singular( 'location' ) ) {
include dirname( __FILE__ ) . '/templates/location.php';
}
else {
return $content;
}
}
Could this be the issue? Would it work better if I had a single template with this code on it instead?
EDIT: I've tried including this code and also the solution below in the single template file directly and it still returns nothing.
First, make sure you're placing this code within the main WordPress loop so you have access to $post. If you're not, you'll need to declare with global $post;.
if ($post->post_parent) {
$children = wp_list_pages(array(
'title_li' => '',
'child_of' => $post->post_parent, // child of only the parent page
'echo' => 0, // do not echo
'exclude' => $post->ID, // exclude the parent page from being added to array
'post_type' => 'location' // only posts from the location post type
));
}
if ($children) {
echo '<ul>' . $children . '</ul>';
}
You should be able to work this into your theme file and display any other info you want to outside of this. You could also do a foreach() loop on $children if you needed to in in case you need to add other content. I have this exact code running on a theme and it is working as intended. This does not get the page content, just the page titles with links. If I understand correctly, that's what you're looking for.
Change pet_pages to get_posts, then modify the arguments you pass in.
<?php
$args = array(
'post_type' => 'location',
'parent ' => $post->ID,
'sort_column' => 'menu_order',
'sort_order' => 'asc',
// etc...
);
$locations = get_posts($args);
?>
Important here is to set the post_type to your custom post-type. If you set the parent config to the current $post->ID, not necessary to also set child_of.
Alright, it's a bit of a kludge, but it works...
<?php
$post_id = $post->ID;
$level = count(get_post_ancestors( $post_id )) + 1;
switch($level) {
case 1: ?>
<?php $args = array( 'child_of' => $post_id, 'parent ' => $post_id,'hierarchical' => 0, 'sort_column' => 'menu_order', 'sort_order' => 'asc', 'post_type' => 'location',);
$mypages = get_pages( $args );
foreach( $mypages as $post ): ?>
<?php
$post_id = $post->ID;
$level = count(get_post_ancestors( $post_id )) + 1;
switch($level) {
case 1: ?>
<?php break;
case 2: ?>
<?php $location = get_field('location', $post->ID); ?>
<div class="location-single" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>">
<h4><?php echo get_the_title($post->ID); ?></h4>
<address><?php echo $location['address']; ?></address>
<time><?php the_field('hours',$post->ID); ?></time>
</div>
<?php break;
}; ?>
<?php endforeach; ?>
<?php break;
case 2: ?>
<?php $args = array( 'child_of' => $post_id, 'parent ' => $post_id,'hierarchical' => 0, 'sort_column' => 'menu_order', 'sort_order' => 'asc', 'post_type' => 'location',);
$mypages = get_pages( $args );
foreach( $mypages as $post ): ?>
<?php
$post_id = $post->ID;
$level = count(get_post_ancestors( $post_id )) + 1;
switch($level) {
case 1: ?>
<?php break;
case 2: ?>
<?php break;
case 3: ?>
<?php $location = get_field('location', $post->ID); ?>
<div class="location-single" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>">
<h4><?php echo get_the_title($post->ID); ?></h4>
<address><?php echo $location['address']; ?></address>
<time><?php the_field('hours',$post->ID); ?></time>
</div>
<?php break;
}; ?>
<?php endforeach; ?>
<?php break;
case 3: ?>
<?php $location = get_field('location', $post_id); ?>
<div class="location-single" data-lat="<?php echo $location['lat']; ?>" data-lng="<?php echo $location['lng']; ?>">
<h4><?php the_title(); ?></h4>
<address><?php echo $location['address']; ?></address>
<time><?php the_field('hours'); ?></time>
</div>
<?php break;
}; ?>
I'm basically looping through the loop and either printing nothing depending on the level of hierarchy.
EDIT: nevermind, it's not passing the post ID's into the nested loops.
Found the answer for my usecase:
Instead of get_pages or get_posts I'm using new WP_Query. that solved all my problems. Thank you everyone for helping.
i have create custom post type for show plans and i want to show post according to category. i am using below code in functions.php for creating custom post type for plans.
add_action('init', 'create_post_types');
function create_post_types() {
register_post_type( 'numbers_plan',
array(
'labels' => array(
'name' => __( 'Numbers plan' ),
'singular_name' => __( 'Numbers plan' )
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'Numbers plan'),
)
);
// Add new taxonomy(like categories)
$labels = array(
'name' => _x( 'PlanCat', 'numbers_plan', 'textdomain' ),
'singular_name' => _x( 'PlanCat', 'numbers_plan', 'textdomain' ),
'search_items' => __( 'Search PlanCat', 'numbers_plan' ),
'all_items' => __( 'All PlanCat', 'numbers_plan' ),
'parent_item' => __( 'Parent PlanCat', 'numbers_plan' ),
'parent_item_colon' => __( 'Parent PlanCat:', 'numbers_plan' ),
'edit_item' => __( 'Edit PlanCat', 'numbers_plan' ),
'update_item' => __( 'Update PlanCat', 'numbers_plan' ),
'add_new_item' => __( 'Add New PlanCat', 'numbers_plan' ),
'new_item_name' => __( 'New PlanCat Name', 'numbers_plan' ),
'menu_name' => __( 'PlanCat', 'numbers_plan' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'numbers_plan' ),
);
register_taxonomy( 'numbers_plans', array( 'numbers_plan' ), $args );
}
for show plans i have create plan.php page with blow code.
<?php
$plan_group = get_terms( 'numbers_plans' );
?>
<?php
foreach ( $plan_group as $plan_group_term ) {
$plan_group_query = new WP_Query( array(
'post_type' => 'numbers_plan',
'tax_query' => array(
array(
'taxonomy' => 'numbers_plans',
'field' => 'slug',
'terms' => array( $plan_group_term->slug ),
'operator' => 'IN'
)
)
));
?>
<h2><?php echo $plan_group_term->name; ?></h2>
<ul>
<?php
if ( $plan_group_query->have_posts() ) : while ( $plan_group_query->have_posts() ) : $plan_group_query->the_post(); ?>
<div>
<div><?php echo the_title(); ?></div>
<div><?php the_field('plan_minutes'); ?></div>
<div><?php the_field('monthly_cost'); ?></div>
<div><?php the_field('cost_of_additional_minutes'); ?></div>
<?php echo do_shortcode("[ARForms_popup id=103 desc='Buy Now' type='link' height='540' width='800']"); ?>
<br/>
</div>
<?php endwhile; endif; ?>
</ul>
<?php
// Reset things, for good measure
$plan_group_query = null;
wp_reset_postdata();
}
?>
it is showing all categories posts but i want to show only one category and it's post. please tell me how can i do this.
One way to select posts from a certain category is by creating a small if statement around the post output. See the example below:
<?php
if (in_category('<category_name')) {
/* the post */
}
else {
/* Do nothing */
}
?>
A full example:
<?php if ( have_posts() ) :
if (in_category('Algemeen')) {
require_once('category-pages/Algemeen-category.php');
} elseif (in_category('Sport')) {
require_once('category-pages/Sport-category.php');
} elseif (in_category('Economie')) {
require_once('category-pages/Economie-category.php');
} elseif (in_category('Politiek')) {
require_once('category-pages/Politiek-category.php');
} elseif (in_category('Gemeente nieuws')) {
require_once('category-pages/Gemeente-category.php');
}
?>
In this example i check each post on it's category and load a different template file for the posts with the corresponding category
exclude all the othe categories id in array.
<?php
$args = array('exclude'=> array("Enter Other categories ID here")); //which categories you dont want
$$plan_group = get_terms('numbers_plans', $args);
?>
I Hope this will help you
<?php
$catquery = new WP_Query( 'cat=3&posts_per_page=10' );
while($catquery->have_posts()) : $catquery->the_post();
?>
<ul>
<li><h3><a href="<?php the_permalink() ?>" rel="bookmark"><?php
the_title(); ?></a></h3>
<ul><li><?php the_content(); ?></li>
</ul>
</li>
</ul>
<?php endwhile; ?>
In the current website i am building i build the following functionality.
Current situation to give a better understanding of the problem.
There is a page called blog. This page display's all the blogs (posts) in a list. There is a aside with all the categories the posts have. The user can select a category. Once the user clicks on it the user will go to the category.php and see all the posts that have that specific category.
I want to create the same scenario but than with a custom post type. I have a template part; 'offer-list-template.php'
offer-list-template.php (here i get all the offers and display them);
<?php
// set up or arguments for our custom query
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$query_args = array(
'post_type' => 'Offers',
'posts_per_page' => 10,
'paged' => $paged
);
// create a new instance of WP_Query
$the_query = new WP_Query( $query_args );
?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); // run the loop ?>
<?php
//$objectData is used in post-listing-item.php
$objectData->title = get_the_title($post);
$objectData->content = get_the_content($post);
$objectData->permalink = get_the_permalink($post);
$objectData->thumbnail = get_the_post_thumbnail($post);
$objectData->posttype = get_post_type($post);
include(locate_template('template-parts/post-listing-item.php'));
?>
<?php endwhile; ?>
In the same file there is the aside which shows the categories. offer_category is the taxonomy slug.
<?php $terms = get_terms( 'offer_category' );
foreach ( $terms as $term ) {
// The $term is an object, so we don't need to specify the $taxonomy.
$term_link = get_term_link( $term );
// If there was an error, continue to the next term.
if ( is_wp_error( $term_link ) ) {
continue;
}
// We successfully got a link. Print it out.
echo '<li>' . $term->name . '<span>('. $term->count . ')</span></li>';
}
?>
</ul
The result is:
If the user clicks on the categorie it goes to: taxonomy-offer-category.php (taxonomy-slug.php)
Here i need to display the posts (post_type->offers) that have the selected category.
Registration of the custom post type:
//Register Custom post type for Offers.
function create_posttype_offer() {
$args = array(
'labels' => array(
'name' => __('Offers', ''),
'singular_name' => __('Offer'),
'all_items' => __('All Offers'),
'add_new_item' => __('Add New Offer'),
'edit_item' => __('Edit Offer'),
'view_item' => __('View Offer')
),
'public' => true,
'has_archive' => true,
'rewrite' => array('slug' => 'Offers'),
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'capability_type' => 'page',
'supports' => array('title', 'editor', 'thumbnail'),
'exclude_from_search' => true,
'menu_position' => 70,
'has_archive' => true,
'menu_icon' => 'dashicons-star-filled'
);
register_post_type('Offers', $args);
}
add_action( 'init', 'create_posttype_offer');
// Register Custom Categoeries for Custom Post Type Offers
function taxonomies_offer() {
$labels = array(
'name' => _x( 'Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Categories' ),
'all_items' => __( 'All Categories' ),
'parent_item' => __( 'Parent Category' ),
'parent_item_colon' => __( 'Parent Category:' ),
'edit_item' => __( 'Edit Category' ),
'update_item' => __( 'Update Category' ),
'add_new_item' => __( 'Add New Category' ),
'new_item_name' => __( 'New Category' ),
'menu_name' => __( 'Categories' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
);
register_taxonomy( 'offer_category', 'offers', $args );
}
add_action( 'init', 'taxonomies_offer', 0 );
When i use the default post type and i call category.php which has the following code is will display the posts with the selected category. But with a custom post type i can't find a way to manage it.
<?php if (have_posts() ) : while ( have_posts() ) : the_post(); // run the loop ?>
<?php
//$objectData is used in post-listing-item.php
$objectData->title = get_the_title($post);
$objectData->content = get_the_content($post);
$objectData->permalink = get_the_permalink($post);
$objectData->thumbnail = get_the_post_thumbnail($post);
$objectData->posttype = get_post_type($post);
include(locate_template('template-parts/post-listing-item.php'));
?>
<?php endwhile; ?>
This is the post-listing-item (view)
<article class="post-item">
<figure>
<?php echo $objectData->thumbnail ?>
</figure>
<div class="content">
<a href="<?php echo $objectData->permalink ?>">
<h2><?php echo $objectData->title ?></h2>
</a>
<p><?php echo $objectData->content ?></p>
<div class="read-more-button">
<a href="<?php echo $objectData->permalink ?>">read more
<span>
<svg class="next-arrow"><use xlink:href="#next-arrow" /></svg>
</span>
</a>
</div>
</div>
</article>
By understanding, you have to have a query for having all the custom taxonomy post to load by the following code:
$terms = get_terms(
array(
'taxonomy' => 'offer_category',
'hide_empty' => false,
)
);
foreach ($terms as $term){
$args = array(
'post_type' => 'Offers',
'tax_query' => array(
array(
'taxonomy' => 'offer_category',
'field' => 'slug',
'terms' => $term->slug,
),
),
);
$query = new WP_Query($args);
if($query->have_posts()): while($query->have_posts()): $query->the_post();
the_title();
the_content();
endwhile;
wp_reset_postdata();
endif;
}
Hope this works for you
I found it!
I got the taxonomy and slug from the url and used that in the query.
<?php
$term_slug = get_query_var( 'term' );
$taxonomyName = get_query_var( 'taxonomy' );
$the_query = new WP_Query( array(
'post_type' => 'offers',
'tax_query' => array(
array (
'taxonomy' => $taxonomyName,
'field' => 'slug',
'terms' => $term_slug,
)
),
));
?>
<ul>
<?php while($the_query->have_posts()) : $the_query->the_post(); ?>
<li><?php the_title(); ?></li>
<?php endwhile; wp_reset_query(); ?>
</ul>
I have created a Taxonomy Meta Data for Custom Post Type and its working fine while saving, updating, editing etc. But its not working while importing or exporting with wordpress importer. Taxonomies meta data are not importing.
Here is the Code based on the Tutorial
<?php
if ( ! function_exists( 'register_cpt_houses' ) ) {
function register_cpt_houses() {
$labels = array(
'name' => __('houses', 'my_plugin'),
'singular_name' => __('houses', 'my_plugin'),
'add_new' => __('Add New','my_plugin'),
'add_new_item' => __('Add New Slide','my_plugin'),
'edit_item' => __('Edit houses','my_plugin'),
'new_item' => __('New houses','my_plugin'),
'view_item' => __('View houses','my_plugin'),
'search_items' => __('Search houses','my_plugin'),
'not_found' => __('No houses found','my_plugin'),
'not_found_in_trash'=> __('No houses found in Trash','my_plugin'),
'parent_item_colon' => '' ,
'all_items' => __( 'All houses' ,'my_plugin')
);
$args = array(
'labels' => $labels,
'public' => true,
'exclude_from_search'=> false,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array('slug'=>'houses', 'with_front' => true ),
'query_var' => false,
'menu_position' => null,
'supports' => array('title', 'thumbnail', 'page-attributes')
);
register_post_type('houses',$args);
}
add_action('init', 'register_cpt_houses');
}
function register_feature_taxonomy() {
$labels = array(
'name' => _x( 'Features', 'taxonomy general name', 'my_plugin' ),
'singular_name' => _x('Features', 'taxonomy singular name', 'my_plugin'),
'search_items' => __('Search Feature', 'my_plugin'),
'popular_items' => __('Common Features', 'my_plugin'),
'all_items' => __('All Features', 'my_plugin'),
'edit_item' => __('Edit Feature', 'my_plugin'),
'update_item' => __('Update Feature', 'my_plugin'),
'add_new_item' => __('Add new Feature', 'my_plugin'),
'new_item_name' => __('New Feature:', 'my_plugin'),
'add_or_remove_items' => __('Remove Feature', 'my_plugin'),
'choose_from_most_used' => __('Choose from common Feature', 'my_plugin'),
'not_found' => __('No Feature found.', 'my_plugin'),
'menu_name' => __('Features', 'my_plugin'),
);
$args = array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
);
register_taxonomy('house_feature','houses', $args);
}
add_action( 'house_feature_add_form_fields', 'add_feature_group_field', 10, 2 );
function add_feature_group_field($taxonomy) {
global $feature_groups;
?><div class="form-field term-group">
<label for="featuret-group"><?php _e('Feature Group', 'my_plugin'); ?></label>
<select class="postform" id="equipment-group" name="feature-group">
<option value="-1"><?php _e('none', 'my_plugin'); ?></option><?php foreach ($feature_groups as $_group_key => $_group) : ?>
<option value="<?php echo $_group_key; ?>" class=""><?php echo $_group; ?></option>
<?php endforeach; ?>
</select>
</div><?php
}
add_action( 'created_house_feature', 'save_feature_meta', 10, 2 );
function save_feature_meta( $term_id, $tt_id ){
if( isset( $_POST['feature-group'] ) && '' !== $_POST['feature-group'] ){
$group = sanitize_title( $_POST['feature-group'] );
add_term_meta( $term_id, 'feature-group', $group, true );
}
}
add_action( 'house_feature_edit_form_fields', 'edit_feature_group_field', 10, 2 );
function edit_feature_group_field( $term, $taxonomy ){
global $feature_groups;
// get current group
$feature_group = get_term_meta( $term->term_id, 'feature-group', true );
?><tr class="form-field term-group-wrap">
<th scope="row"><label for="feature-group"><?php _e( 'Feature Group', 'my_plugin' ); ?></label></th>
<td><select class="postform" id="feature-group" name="feature-group">
<option value="-1"><?php _e( 'none', 'my_plugin' ); ?></option>
<?php foreach( $feature_groups as $_group_key => $_group ) : ?>
<option value="<?php echo $_group_key; ?>" <?php selected( $feature_group, $_group_key ); ?>><?php echo $_group; ?></option>
<?php endforeach; ?>
</select></td>
</tr><?php
}
add_action( 'edited_house_feature', 'update_feature_meta', 10, 2 );
function update_feature_meta( $term_id, $tt_id ){
if( isset( $_POST['feature-group'] ) && '' !== $_POST['feature-group'] ){
$group = sanitize_title( $_POST['feature-group'] );
update_term_meta( $term_id, 'feature-group', $group );
}
}
add_filter('manage_edit-house_feature_columns', 'add_feature_group_column' );
function add_feature_group_column( $columns ){
$columns['feature_group'] = __( 'Group', 'my_plugin' );
return $columns;
}
add_filter('manage_house_feature_custom_column', 'add_feature_group_column_content', 10, 3 );
function add_feature_group_column_content( $content, $column_name, $term_id ){
global $feature_groups;
if( $column_name !== 'feature_group' ){
return $content;
}
$term_id = absint( $term_id );
$feature_group = get_term_meta( $term_id, 'feature-group', true );
if( !empty( $feature_group ) ){
$content .= esc_attr( $feature_groups[ $feature_group ] );
}
return $content;
}
add_filter( 'manage_edit-house_feature_sortable_columns', 'add_feature_group_column_sortable' );
function add_feature_group_column_sortable( $sortable ){
$sortable[ 'feature_group' ] = 'feature_group';
return $sortable;
}
?>
What am I doing wrong?
If you need to export the data in termmeta table then try this plugin to export the termmeta data in separate XML file.
Export custom post type will only get you connection between the taxonomy ID and Post exported.
To get the Meta data of that taxonomy try this plugin It will provide you a XML containing all additional entries of that Taxonomy you can import that too
https://wordpress.org/plugins/wp-export-categories-taxonomies/
You will find this in Tools -> Wp Export Cats & Taxs
Select the Taxonomy in custom post types you want to export ..
I created a filterable portfolio using the tutorial found here:http://zoerooney.com/blog/web-development/filtering-portfolio-quicksand-taxonomies/#comments
Everything is working but I can not set my post per page. My portfolio goes by the number set in the Setting>Reading>Blog Pages Show at Most.
I tried using 'posts_per_page' =>'-1' but it does not work. Maybe I have it in the wrong place.
This is code in my functions file for my custom post type and categories for my portfolio items:
register_taxonomy("pftype", array("portfolio"), array("hierarchical" => true,"label" => "Project Types", "singular_label" => "Project Type"));
add_action('init', 'cptui_register_my_cpt_portfolio');
function cptui_register_my_cpt_portfolio() {
register_post_type('portfolio', array(
'label' => 'Portfolio',
'description' => '',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'post',
'map_meta_cap' => true,
'hierarchical' => false,
'rewrite' => array('slug' => 'portfolio', 'with_front' => true),
'query_var' => true,
'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes','post-formats'),
'labels' => array (
'name' => 'Portfolio',
'singular_name' => 'Portfolio',
'menu_name' => 'Portfolio',
'add_new' => 'Add Portfolio',
'add_new_item' => 'Add New Portfolio',
'edit' => 'Edit',
'edit_item' => 'Edit Portfolio',
'new_item' => 'New Portfolio',
'view' => 'View Portfolio',
'view_item' => 'View Portfolio',
'search_items' => 'Search Portfolio',
'not_found' => 'No Portfolio Found',
'not_found_in_trash' => 'No Portfolio Found in Trash',
'parent' => 'Parent Portfolio',
)
) ); }
And this is the code I'm using for my portfolio page:
<?php
/**
* Template Name: Portfolio
*/
?>
<?php get_header(); ?>
<ul class="load-portfolio">
<li class="active">All</li>
<?php
$args = array( 'taxonomy' => 'pftype' );
$terms = get_terms('pftype', $args);
$count = count($terms); $i=0;
if ($count > 0) {
$cape_list = '';
foreach ($terms as $term) {
$i++;
$term_list .= '<li>' . $term->name . '</li>';
if ($count != $i) $term_list .= ''; else $term_list .= '';
}
echo $term_list;
}
?>
</ul>
<ul class="portfolio-grid">
<?php
$pfportfolio = new WP_Query( 'post_type=portfolio' );
while ( $pfportfolio->have_posts() ) : $pfportfolio->the_post();?>
<?php
echo '<li data-id="post-'.get_the_ID().'" data-type="'.$terms_as_text = strip_tags( get_the_term_list( $post->ID, 'pftype', '', ' ', '' ) ).'">';
?>
<div class="item">
<div class="view third-effect">
<?php the_post_thumbnail( 'homepage-thumb' ); ?>
<?php
?>
<div class="mask">
</div>
<div class="item-title"><?php the_title(); ?></div>
</div>
</div>
<?php
echo '</li>';
endwhile;
wp_reset_postdata();
?>
</ul>
<?php get_footer(); ?>
I figured it out. I had to replace:
$pfportfolio = new WP_Query( 'post_type=portfolio' );
With this in my page template:
$pfportfolio = new WP_Query('paged=$paged&showposts=-1&'.$query."post_type=portfolio");