Posts not showing content after migration

As suggested by Jos the reason for this was that the post_name column in the wp_posts table was empty. To correct the said problem, the following steps were taken: Backup the database. Check for duplicates in the database. select * from (select count(*) as c, post_title from wp_posts where post_name=”” and post_type=”post”) as counts where … Read more

Create/Set Category as Title of Post

Can’t give you fish, but I can try you to teach how to fish with a couple of pointers; hook into publish_post (good example code there) and / or post_updated in the function that is called that way, use wp_create_category (which will only create if the cat. name doesn’t exist yet) and with the cat … Read more

Count singular post views automatically

You could hook into template_redirect and execute a helper function: add_action( ‘template_redirect’, ‘wpse_75558_count’ ); function wpse_75558_count() { if ( is_singular() ) setPostViews( get_the_ID() ); } To display the post views, you have to use a later hook. I would recommend the_content: add_filter( ‘the_content’, ‘wpse_75558_show_count’ ); function wpse_75558_show_count( $content ) { $count = getPostViews( get_the_ID() ); … Read more

How to 301 redirect from url with post id to permalink with post name (slug)?

yes, it is possible. add a template_redirect hook handler: add_filter(‘template_redirect’, ‘redirect_post_to_canonical_url’); function redirect_post_to_canonical_url(): void { if (!is_single()) { // do not redirect nothing else except posts return; } $canonicalLocation = get_permalink(); $requestUri = $_SERVER[‘REQUEST_URI’]; $currentLocation = home_url(“https://wordpress.stackexchange.com/”) . substr($requestUri, 1); if ($currentLocation === $canonicalLocation) { // prevent from infinite redirect loop return; } wp_redirect($canonicalLocation, 301); … Read more