Search Custom Post Type & Taxonomies

For now I’ve just redirected the default search string (www.sitedomain.com/?s=keyword) to www.sitedomain.com/trade/keyword, (trade is my custom taxonomy) although I’m pretty sure this isn’t the correct or best way to do it so it’d be great if someone else has a better solution. Here is the code for redirecting the search string: function redirect_search() { if … Read more

Custom Post Type Capabilities

Ok – lets try this again 🙂 I added the map_meta_cap parameter which is needed to have delete_others_posts work. Now I was able to get authors to edit and view all posts but only delete their own. $labels = array( ‘name’ => __( ‘Book’, ‘textdomain’ ), ‘singular_name’ => __( ‘Book’, ‘textdomain’ ), ‘menu_name’ => __( … Read more

uploading images to specified directories

This might be perfect solution for you: http://wordpress.org/plugins/custom-upload-dir/ With that plugin you can have upload folder structure as you wish: “uploads/$image_type./.$client./.$post_title./” or uploads/category/subcategory/post_title/ Or anything you like, you can combine post title, category, post author, post date and many more in your folder structure.

Rewrite slug of custom post type to include post-id

Try this : function change_post_type_link( $link, $post = 0 ){ if ( $post->post_type == ‘questions’ ){ return home_url( ‘questions/’. $post->post_name .”https://wordpress.stackexchange.com/”. $post->ID ); } else { return $link; } } add_action( ‘init’, ‘change_rewrites_init’ ); function change_rewrites_init(){ add_rewrite_rule( ‘questions/([a-z-]+)/([0-9]+)?$’, ‘index.php?post_type=questions&p=$matches[1]&postid=$matches[2]’, ‘top’ ); } Here post slug is attached after questions in the URL. For example questions/q-slug/45. … Read more

Add an option in a builder

You can create a custom query with WP_Query to get all posts from your post type. This is how a basic query will look like, you just need to tweak it to your needs <?php // The Query $the_query = new WP_Query( ‘post_type=project&posts_per_page=-1’ ); // The Loop if ( $the_query->have_posts() ) { while ( $the_query->have_posts() … Read more

Query posts and custom post types within the same category

It sounds like all you need to do is specify the ‘post_type’ argument which is only ‘post’ by default. $posts = get_posts( array( ‘category’ => 16, ‘post_type’ => array( ‘post’, ‘{another_post_type}’, ‘{another_post_type}’, ‘{another_post_type}’ ) ) ); You might also consider using WP_Query to make a custom loop instead. That’s a bit personal preference but is … Read more