do more action after I publish a post

There are a number of hooks you can use, such as publish_post or save_post, e.g.: // an example of a post save hook add_action( ‘save_post’, ‘diligents_post_save_hook’ ); function diligents_post_save_hook( $post_id ) { //verify post is not a revision if ( !wp_is_post_revision( $post_id ) ) { // do things } } save_post will fire on publish … Read more

post category in wp_insert_post

I did not actually test your code thoroughly, but on the first glimpse: your form input is named post_category while you’re grabbing $_POST[‘new_cat’]. Adjusting that (e.g., set both to post_category) should already do. // EDIT And why are you grabbing $_POST[‘category’] in line 5?

While loop articles – if statement order

Prepare the query before you loop over it: $first = array_shift( $the_query->posts ); $second = array_shift( $the_query->posts ); // now re-add in reverse order array_unshift( $the_query->posts, $first ); array_unshift( $the_query->posts, $second ); // this is now the first item while ($the_query -> have_posts()) : $the_query -> the_post(); // regular loop

How to get posts and comments amount per hour, per year and per month?

For comments: function count_comments_in_period( $date_from, $date_to ){ global $wpdb; $count = $wpdb->get_var( $wpdb->prepare(“SELECT COUNT(*) FROM {$wpdb->comments} WHERE comment_date >= %s AND comment_date < %s “, $date_from, $date_to)); return $count; } Just use dates in yyyy-mm-dd format. For posts: function count_posts_in_period( $date_from, $date_to ){ global $wpdb; $count = $wpdb->get_var( $wpdb->prepare(“SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_date >= … Read more

Dynamically switch template on click

My answer is something like an application of one of the @allenericr answer points + some cache. I suggest to implement this only if the 3 templates are different in the content and not only in the aspect, otherwise a CSS + JS solution should be the best choice. Create a main page template ‘multi-template-page.php’ … Read more

why does wordpress ignore the post args?

There is no category argument: cat (int) – use category id. category_name (string) – use category slug (NOT name). category__and (array) – use category id. category__in (array) – use category id. category__not_in (array) – use category id. You want to be using the category_name argument– note that it takes the slug not the name–, though … Read more