Change post-name when inserting new Post if Specific Category is selected in WP

You can use the wp_insert_post_data filter, and check the post_category array for your category ID. (If $update is false, you’ll know it’s a new post being added, not an existing post being edited.) Something like this should work. add_filter( ‘wp_insert_post_data’, ‘wpse414180_maybe_change_slug’, 10, 4 ); /** * Changes the slug on posts in the Poetry category. … Read more

Count the number of matching post names in foreach loop

I would get the count of a variable number of repeated titles by using an indexed array. $theposts = get_posts( array( ‘post_type’ => ‘post_subscriber’, ‘post_status’ => ‘publish’, ‘numberposts’ => -1, ) ); // project titles counter, outside the loop $project_titles = array(); foreach( $theposts as $p ): $project_name = get_post_meta($p->ID, ‘project’, true); echo ‘<ol>’; echo … Read more