WordPress custom posts and permalinks

Try something similar to this: function custom_rewrite( $wp_rewrite ) { $feed_rules = array( ‘(.+)/([^/]+)(/[0-9]+)?/?$’ => ‘index.php?post_type=”.$wp_rewrite->preg_index(1).”&custom_taxonomy=’. $wp_rewrite->preg_index(2).’&post_name=”. $wp_rewrite->preg_index(3) ); $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules; } // refresh/flush permalinks in the dashboard if this is changed in any way add_filter( “generate_rewrite_rules’, ‘custom_rewrite’ ); You may need to modify the regex, as regex isn’t one of my … Read more

Easiest way to have closed comments on a custom post type

Template Tags for the rescue Only logged in users: is_user_logged_in() Only logged in users that have a certain capability assigned to their role current_user_can($capability) Only logged in users that have a specific role assigned current_user_has_role($role) Only logged in users that have a specific capability assigned (to their role) on a specific blog current_user_can_for_blog($blog_id, $capability)

Galleries of images attached to posts

If you plan on using WP’s built-in image custom fields, include this query on your single-project.php (assuming galleries will only be called on single project pages): // this will get all images attached to that specific post $imagequery = new WP_Query( array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image/jpeg’, ‘post_parent’ => $post->ID )); if ($imagequery->have_posts()) { … Read more

Custom Post Type Meta Box Text Input Field Won’t Save When Blank

The problematic line is this one: if (isset($_POST[“book_title”]) && $_POST[“book_title”] <> ”) update_post_meta($post->ID, “book_title”, $_POST[“book_title”]); That logic says: If the submitted form contains a field called ‘book_title’ and if the content of the ‘book_title’ field does not equal an empty string, then save it. In your situation, the first condition should be met (HTML input … Read more

Need help with simple “if statement” checks to output particlular CPT data depending on what client uploads/fills out

You’ve got some basic syntax problems. Your elseif statement wasn’t actually checking anything and wasn’t properly wrapped in parenthesis. The logic more appropriately checks if the first condition is true, then if the second condition is true, and finally if all else fails, display the hard coded image. <?php $meta_box_topbanner_url = get_post_meta( $post->ID, ‘meta_box_topbanner_url’, true … Read more