• I have found today this little plugin and I checked the code. I think there is a little improvement in one of the filters.
    I post it here, just in case someone can give me feedback on the code.
    It seems to work for me. I have assigned the same category to post and pages and the pages are listed in the category page.


    // error_log($wp_query->get(‘post_type’));
    if ( empty($wp_query->get(‘post_type’)) || $wp_query->get(‘post_type’) === ‘post’){

    if ($wp_query->get(‘tag’)) $wp_query->set(‘post_type’, [‘post’,’page’]);
    // category query
    if ($wp_query->get(‘category_name’)) $wp_query->set(‘post_type’, [‘post’,’page’]);
    }`

    I modified the hook ‘pre_get_posts’ to set post_type only for post type ‘post’ or ’empty’ and sets only two post types. Otherwise it does the same for different post_types as menus and other post types (Contact Forms) that share ‘posts’ database.
    Un-comment the error_log line to see how many times the hook is called.

  • The topic ‘Need feedback about improvement of this code’ is closed to new replies.