User Selectable Delete of Pages

You are deleting all pages with that code because you are triggering the function wp_delete_post(). You should build the url to delete the page(or post) like this: $delLink = wp_nonce_url( get_bloginfo(‘wpurl’) . “/wp-admin/post.php?action=delete&post=” . $page->ID, ‘delete-post_’ . $page->ID); So your code should be: $pages = get_pages(); foreach ( $pages as $page ) { $delLink = … Read more

How to add category post count in main navigation menu [closed]

This can be achieved many ways. But, the below method is most prominent to me. add_filter(‘the_title’, ‘wpse165333_the_title’, 10, 2); function wpse165333_the_title($title, $post_ID) { if( ‘nav_menu_item’ == get_post_type($post_ID) ) { if( ‘taxonomy’ == get_post_meta($post_ID, ‘_menu_item_type’, true) && ‘category’ == get_post_meta($post_ID, ‘_menu_item_object’, true) ) { $category = get_category( get_post_meta($post_ID, ‘_menu_item_object_id’, true) ); $title .= sprintf(‘ (%d)’, $category->count); … Read more

Archiving posts in wordpress

You can do that with two ways. 1. You can modify the WordPress main query to force WordPress to show posts older than 30 days on archive pages and on blog page, show posts before 30 days. You can limit posts with the help of date_query. Paste this function in your functions.php file. This should … Read more

Wrong post title displayed from loop

Welcome the the WordPress Stack Exchange and congrats on your first post! First off, you may not want to use query_posts() here. Second off – the_post() needs to be before the_title() as it sets up all the posts functions such as the_title(), the_permalink() etc. and queues the next post in your while loop. Your Loop … Read more

Help diagnosing scheduled post problem with transition_post_status

By default add_action() only passes one parameter, not all three. Change your function to: add_action( ‘transition_post_status’, function ( $new_status, $old_status, $post ) { if( ‘publish’ == $new_status && ‘publish’ != $old_status ) { wp_die(‘STOP’); } }, 10, 3 ); Edited to add: The transition_post_status hook fires after the post transition from future to publish has … Read more

Hide posts belongs to few categories in homepage

You can do this with pre_get_posts. This hook is called after the query variable object is created, but before the actual query is run. For excluding category id 32 and 39 from homepage, you can setup a function like this. function wpse_exclude_categories( $query ) { if ( is_admin() ) return; if ( $query->is_home() && $query->is_main_query() … Read more

How Do I Get My Post Tags to Alphabetize?

You could use the filter term_links-post_tag to sort tags while ignoring their case: add_filter( “term_links-post_tag”, ‘themeslug_sort_tags_alphabetically’ ); function themeslug_sort_tags_alphabetically( $tags ){ natcasesort( $tags ); return $tags; } This code is to be placed in the functions.php of the child theme.

Exclude current custom post on single post

Refer to the WP_Query Codex page for a full list and explanation of parameters. The one you want in this case is post__not_in. $recent = new WP_Query( array( ‘post_type’ => ‘works’ ‘posts_per_page’ => 5, ‘post__not_in’ => array( $currentID ) ) );