Custom post type – how to name file?

If I understood correctly, all you have to do is add ‘publicly_queryable’ => FALSE, to your arguments array. And the individual archive template file would be archive-kalendar_radova.php, that’s right. // Edit In order to have a single view of your CPT be redirected to the according archive, put the following to your functions.php file: function … Read more

Function to limit number of custom post types on homepage – TwentyTen

This should do the trick: add_action( ‘pre_get_posts’, ‘add_tours_post_type_to_query’ ); function add_tours_post_type_to_query( $query ) { if ( is_home() && $query->is_main_query() ){ $query->set( ‘post_type’, array( ‘tours’ ) ); $query->set( ‘posts_per_page’, 1 ); } return $query; } For the future the Codex can be your friend. Exactly this is explained there.

saving dropdown menu data on custom post type

I’ve found my problem. The choice was indeed being saved, just wasn’t showing to me at the editor (it was always showing me the first choice). The thing is, the $selected function compares the selected input with the string provided which, in my case, was incorrectly filled. so the following code: <select name=”estadoDaObra” id=”estadoDaObra”> <option … Read more

Query all post types but limit to parents

In your functions.php you can create a function that will hook into the pre_get_posts hook. Something like (just an example): function alter_query($query){ $query->set(‘post_parent’, 0); } add_action( ‘pre_get_posts’, ‘alter_query’ ); There you can alter the main query. That way while(have_posts()) : the_post(); will still just normally work. (You should check if you are altering the right … Read more

Display custom posts for each category from its custom taxonomy

For those who wanted to know: <?php $cat_args = array( ‘taxonomy’ => ‘service_sections’, ‘orderby’ => ‘slug’, ‘order’ => ‘ASC’ ); $cats = get_categories($cat_args); // passing in above parameters foreach ($cats as $cat) : // loop through each cat $cpt_query_args = new WP_Query( array( ‘post_type’ => ‘services’, ‘service_sections’ => $cat->name ) ); if ($cpt_query_args->have_posts()) : ?> … Read more

insert image with custom post type

Your current code should be correctly creating the post inside your Products post type. You’re missing the bit that updates the post meta holding the image. Assuming the meta_key is product_image, then running this on success should do: update_post_meta( $pid, ‘product_image’, $attachment_id ); on a side note: don’t forget to run wp_generate_attachment_metadata and wp_update_attachment_metadata after … Read more

Find custom post type url by author

Query for post type listing_type and author ID within your loop: $args = array( ‘post_type’ => ‘listing_type’, ‘author’ => get_the_author_meta( ‘ID’ ) ); $listing_post = new WP_Query( $args ); if( $listing_post->have_posts() ){ while( $listing_post->have_posts() ){ $listing_post->the_post(); the_permalink(); } } // reset $post global to original value wp_reset_postdata();