Add post_type to index.php

It would be something like this (goes in functions.php or elsewhere, but not template): add_action( ‘pre_get_posts’, ‘include_dictionnaire_in_home’ ); function include_dictionnaire_in_home( $query ) { if ( ! is_admin() && $query->is_main_query() && $query->is_home() ) { $query->set( ‘post_type’, array( ‘post’, ‘dictionnaire’ ) ); } } Note that index.php template is not strictly home template. It is catch-all template … Read more

$wpdb: Counting posts corresponding to 3 terms in 3 different taxonomies

Do a tax-query and then count the result. No need for a custom query with dozens of JOINS. $posts = new WP_Query( array( ‘post_type’ => ‘MYPOSTTYPE’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘TAX_1’, ‘field’ => ‘slug’, ‘terms’ => array( ‘TERM_TAX_1’ ), ‘operator’ => ‘IN’ ), array( // etc. ) ), ‘post_status’ => ‘publish’ ); prinft( … Read more

Save an array from drop-down in custom meta box

Quite simple. Instead of saving the post title, save the post ID, so in the front end you can extract all necessary info. Like so: get_post( $the_saved_ID_value ); or get_permalink( $the_saved_ID_value );. In you code, change this line: echo ‘<option value=”‘.get_the_ID().'” ‘.$is_selected.’>’.get_the_title().'</option>’; Notes: Using a WP_Query seems a bit too much, consider get_posts. Lots of … Read more

Insert data on comment post

Not sure what you’re after but this is how you would get the content of a newly posted comment add_action( ‘comment_post’, ‘my_comment_callback’ ); function my_comment_callback($id) { $comment = get_comments(array( ‘ID’ => $id )); // $content is the actual text the user posted $content = $comment->comment_content; } Is that what you’re looking for?

Excluding custom post types

This function could help you filter out non standard post types: function is_non_standard_type($id = null) { if (!$id) { // rewind_posts(); global $post; $id = $post->ID; } $post_type = get_post_type( $id ); return in_array($post_type, array(‘post’, ‘page’, ‘attachment’, ‘nav_menu, ‘nav_menu_item’, ‘revision’)); // You might want to handle revision differently } Keep in mind though that this … Read more

Edit / delete custom post types through web page (not admin)

Take a look at http://wordpress.org/extend/plugins/front-end-editor/ If you assign users the Contributor role, they’ll be able edit their own posts from the frontend. You could use a basic redirect to prevent Contributors from being shown the admin panel on login… look around StackExchange/Google for several solutions to this. For another solution, which will give you more … Read more