Related posts loop based on tags AND categories doesn’t work without at least one tag assigned

You haven’t accounted for the case that there are no tags assigned in your declaration of $tag_related_posts. Your get_posts function always returns results in your line of code: $tag_related_posts = get_posts(‘exclude=” . $post->ID . “&numberposts=” . $max_articles . “&tag=’ . $tags_string); If the $tags_string is null, it just returns a random list of posts and … Read more

Enable post revisions for a specific post

Since the check is made in wp_revisions_to_keep($post) in wp-includes/revision.php, and the result is run through a filter, you should be able to do something like this: <?php function wpse_289553($num, $post) { if(in_array($post->ID, array(123, 456, 789))) { return -1; } return $num; } add_filter(“wp_revisions_to_keep”, “wpse_289553”, 10, 2); Set your post IDs in that array and adjust … Read more

Automatic value for custom fields for posts

Try meta_query to get posts having theme_settings_post_show == true (for new posts) and theme_settings_post_show not set at all (for old posts): <?php $queryArguments = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘post’, ‘meta_query’ => array( ‘relation’ => ‘OR’, // value is not set or true array( ‘key’ => ‘theme_settings_post_show’, ‘value’ => ”, // can be any … Read more

Count total number across post types

Why not just get the count for each post type and sum them? function get_all_them_ven_posts(){ $count= 0; $post_types = [ ‘postType1’, ‘postType2’, ‘postType3’ ]; foreach( $post_types as $post_type ) { $count_posts = wp_count_posts( $post_type ); $count = $count + $count_posts->publish; } return $count; }

Diplay comment date on WP_Post_Comments_List_Table

So, it doesn’t appear you can do much “properly” to solve this issue, however, you can take some advice from this answer and apply it to your problem: <?php add_filter( ‘get_comment_author_IP’, function( $comment_author_IP, $comment_ID, $comment ) { global $pagenow; if( is_admin() && ‘post.php’ === $pagenow && isset( $_GET[‘post’] ) ) { $comment_date = do_something_to_get_comment_date($comment_ID); $comment_author_IP … Read more

How can I get a post field value using javascript?

Can I use the API and a JS ajax function to get the two values? Yes, absolutely. Step 1: (PHP) Registers the custom fields (i.e. add them to the WordPress REST API response for Posts) register_meta( ‘post’, ‘address1’, [ ‘type’ => ‘string’, // string/boolean/integer/number ‘single’ => true, ‘show_in_rest’ => true, ] ); register_meta( ‘post’, ‘address2’, … Read more

Posts page only shows one post

As noted in a comment above, apparently the theme I use in one of its updates required the Options Framework plugin. Without it, a certain function was undefined. Thus the error and the breaking of the posts page. Installing the plugin solved the issue.

How can I remove posts of a certain category from homepage after a specified time period?

This looks straightforward, but unfortunately isn’t, because wp_query doesn’t allow you to exclude posts on basis of multiple arguments (in this case category and date). You can select on basis of multiple arguments, but not exclude. So, to do what you want, you must in some way bundle your two arguments into one. Conceptually, you … Read more

Getting a 404 error when clicking edit page

You mentioned that you disabled all plugins, and changed the theme (I assume you used one of the ‘twenty’ themes, which is what I usually do when trying to find theme/plugin problems). Did you also look at the ‘must use’ plugins (in wp-content/mu-plugins ) (see https://codex.wordpress.org/Must_Use_Plugins ). Maybe a plugin in there is causing problems. … Read more