Custom posts – tag pagination

Your code has a couple of flaws which I’m not going to go into detail now. Here is a short list

  • pre_get_posts is an action

  • On any type of archive page you need to make sure you only target the main query and the front end when using pre_get_posts

  • Your syntax is very hard to debug and not supported by most code editors. Although if (): else : endif; is valid php, it is not recommended due the trouble debugging it. Use proper curlies like if () { } else { }

  • Most of your code does not make much sense. Please see my code and compare it with yours

You can rewrite your code as follows

add_action( 'pre_get_posts', function ( $q )
{
    if (     !is_admin() // Make sure you only target the front end 
          && $q->is_main_query() // Only target the main query
          && $q->is_tag() // Only target the tag pages
    ) {
        $q->set( 'post_type', array( 'post', 'btp_work' ) ); // Change as necessary
    }
});

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)