how to programmatically change post tags

The key function you’re looking for here is wp_set_post_tags(). To add the tag ‘awesome’ to post 98, wp_set_post_tags( 98, array( ‘awesome’ ), true ); Note that the true parameter means that this tag will be added to the existing post tags. If you omit this value, it defaults to false, and the existing post tags … Read more

posts_per_page doesnt work

Yeah, use ‘nopaging’ => true http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters $Poz = array( ‘posts_per_page’ => 3, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘update_post_term_cache’ => false, ‘update_post_meta_cache’ => false, ‘nopaging’ => true, ); $the_query = new WP_Query( $Poz );

Change Order of Admin Posts Depending on Meta

Post list in admin (edit.php) use a normal WP_Query, just like frontend can be changed using pre_get_posts. add_action(‘pre_get_posts’, ‘reorder_my_cpt’); function reorder_my_cpt( $q ) { if ( !is_admin() || !$q->is_main_query() ) { return; } $s = get_current_screen(); // change ‘book’ with your real CPT name if ( $s->base === ‘edit’ && $s->post_type === ‘book’ ) { … Read more

How to change the title url on the edit post screen?

Use get_edit_post_link filter. add_filter(‘get_edit_post_link’, ‘get_edit_post_link_178416’, 99, 3); function get_edit_post_link_178416($link, $post_id, $context) { $scr = get_current_screen(); if ($scr->id == ‘edit-post’ && $context == ‘display’) { return ‘http://google.com’; } else { return $link; } } You can see it’s used here

Group posts by year in loop

This little snippet could help you. $years = array(); if( have_posts() ) { while( have_posts() ) { the_post(); $year = get_the_date( ‘Y’ ); if ( ! isset( $years[ $year ] ) ) $years[ $year ] = array(); $years[ $year ][] = array( ‘title’ => get_the_title(), ‘permalink’ => get_the_permalink() ); } } This code gets all … Read more

Disable single post page

Although I’m also curious as to why you’d want to do this, and would probably suggest using a custom post type instead, this would probably work (actually works for any single post type except pages and attachments): add_action( ‘pre_get_posts’, ‘wpse44983_single_post_404’ ); function wpse44983_single_post_404( $query ) { if ( $query->is_main_query() && $query->is_single() ) { $query->is_404 = … Read more

Check if post exists

WordPress has a post_exists function that returns the post ID or 0 otherwise. So you can do if ( 0 === post_exists( $title ) ) { **YOUR_CODE_HERE** }

Add category to all post by using sql query?

You can run WordPress query to associate category to all posts. Here is the code. What this code will do is check if a post is already in category id 67, if it’s not then it will assign category id to it. <?php $args = array( ‘posts_per_page’ => -1, ‘orderby’ => ‘post_date’ ); $posts = … Read more