WordPress function saves a post twice and updates all posts

It duplicate because when you run the wp_update_post(), it will use the wp_insert_post() function and the action save_post will run again. please use the filter wp_insert_post_data to filter the value before save. https://codex.wordpress.org/Plugin_API/Filter_Reference/wp_insert_post_data Example: function wpse309780_filter_post_data($data , $postarr) { $data[‘post_name’] = wp_count_posts( ‘post’ )->publish; return $data; } add_filter( ‘wp_insert_post_data’, ‘wpse309780_filter_post_data’ );

How can this crude function be improved?

function admin_trim_category_description( $terms, $taxonomies ){ if( ‘category’ != $taxonomies[0] )return $terms; $whatever_categories = array(‘category1’, ‘hidden’, ‘category2’, ‘category3’); foreach( $terms as $key => $term) if(!in_array($terms[$key]->name, $whatever_categories)) $terms[$key]->description = strip_tags(substr( $term->description, 0, 75 )).”…”; else unset($terms[$key]); return $terms; }

Functions.php Problem

I’ve seen in the pastebin the problem and merged the whole code together again. Put this first part completely into your functions.php. /** * Display previous image link that has the same post parent. * * @since 2.5.0 * Original version in /wp-include/media.php * @param string $size Optional, default is ‘thumbnail’. Size of image, either … Read more

Getting comment count per post not working

Try this: <?php $popular = new WP_Query(‘orderby=comment_count&posts_per_page=5’); ?> <?php while ($popular->have_posts()) : $popular->the_post(); ?> <li><a href=”https://wordpress.stackexchange.com/questions/108038/<?php the_permalink(); ?>”><?php the_title(); ?></a> has <?php comments_number( ‘no responses’, ‘one response’, ‘% responses’ ); ?>.</li> <?php endwhile; ?> From the codex.

Conditional functions.php on page template

You can make use of the conditional tag is_page_template() This Conditional Tag allows you to determine if you are in any page template. Optionally checks if a specific Page Template is being used in a Page. This is a boolean function, meaning it returns either TRUE or FALSE. You can try something like if( is_page_template( … Read more

‘Attempt to modify property of non-object’ warning

Some simple php, check if it’s set before trying to unset it. function my_filter_plugin_updates( $value ) { if( isset( $value->response[‘duplicator/duplicator.php’] ) ) unset( $value->response[‘duplicator/duplicator.php’] ); //Duplicator return $value; } add_filter( ‘site_transient_update_plugins’, ‘my_filter_plugin_updates’ );