Setting post_id for single.php based on URL without a redirect

I figured it out, here is the solution for anyone else wondering how to do something like this: function force_ID($query) { global $wpdb; if (substr($_SERVER[‘REQUEST_URI’],-5) == ‘.html’) { $post_id = $wpdb->get_var($wpdb->prepare(“SELECT ID FROM $wpdb->posts WHERE post_name=%s AND post_status=”publish””,substr(basename($_SERVER[‘REQUEST_URI’]),0,-5))); if ($post_id > 0) $query->set(‘page_id’,$post_id); } } add_action(‘pre_get_posts’,’force_ID’); In examining the wp-includes/query.php file, I noticed that the … Read more

Plugin access to average users not only admin

The rules for themes and plugins are basically the same. You can make plugins and themes administrable by anyone in most respects except that non-admins can’t install and uninstall plugins/themes. For instance, you should use the if_current_user_can(‘do_stuff’) conditional to handle permissions on operations. Also, the add_menu_page() function lets you specify what capabilities a user needs … Read more

Setting a post’s category

Try doing this: $insert_post = wp_insert_post(array( ‘post_author’=>1, ‘post_date’=>date(‘Y-m-d H:i:s’), ‘post_date_gmt’=>date(‘Y-m-d H:i:s’), ‘post_content’=>”, ‘post_title’=>”, ‘post_excerpt’=>”, ‘post_status’=>’publish’, ‘comment_status’=>’closed’, ‘post_name’=>”, ‘post_parent’=>0, ‘post_type’=>’portfolio’, // with ‘portfolio’ custom post type ‘post_category’=>array($id), )); if( $insert_post ) { wp_set_object_terms( $insert_post, intval( $id ), ‘galleries’); } Using wp_set_object_terms you can set the terms for the post in any taxonomy. The first argument is … Read more

How to exclude categories from get_categories() select list inside a widget admin panel

Per http://codex.wordpress.org/Class_Reference/WP_Query you would need to prefix the numerical identifier of the array with a minus-sign, such as $query = new WP_Query( ‘cat=-12,-34,-56’ );, which would exclude the categories with the identifier 12, 34 and 56. You could achieve this by changing the get_cats function into the following: function get_cats(){ $exclude_cats = array( get_cat_ID(‘test1’), get_cat_ID(‘test2’), … Read more

How can I create a page as a draft from my plugin?

You can use the function wp_insert_post for this http://codex.wordpress.org/Function_Reference/wp_insert_post $my_post = array( ‘post_title’ => $title, ‘post_content’ => $content, ‘post_status’ => ‘draft’, ‘post_type’ => ‘page’, ‘post_author’ => $author ); wp_insert_post( $my_post ); then you can use wp_mail(); to notify someone. http://codex.wordpress.org/Function_Reference/wp_mail