pre_get_posts on custom post type

pre_get_posts does not work on page templates and static front pages. It will 404. If I read the WP_Query class correctly, the page ID is passed to a parameter such as p once the URL is parsed. You can try unsetting this parameter and check if it changes the query, but I doubt if this will be the only parameter to change to make it work. Have never played around with this, so everything is just pure speculation. This is quite an opportunity for someone to play around with pre_get_posts on page templates

You have to use a custom query here to output what you need. As for pagination, you need to add the following your custom query to make it work

This goes before you define your arguments

$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;

Remember to change 'paged' to 'page' for static front pages

You then need to set the 'paged' parameter in your query arguments

'paged' => $paged,

It is as easy then as to pass the $max_num_pages property of your custom query to your pagination function.

Example

If your custom query looks like this

$q = new WP_Query( $args );

then you need to pass $q->max_num_pages to your pagination function like the following

next_posts_link( 'Next posts', $q->max_num_pages );

EDIT

Just one or two notes on your code

  • If you want to show custom post types on page templates, you need to set has_archive to false, otherwise the archive template will be used to show custom post types

  • If you are talking about getting 404 errors on your custom post type archive template, then you just need to flush your permalinks by visiting the permalink settings page is backend. No need for any type of custom code or filters.

EDIT 2

From your paste (which should be an edit to your question), you have a few small issues here

  • wp_reset_query() is wrong. It is used with query_posts which you should never use. You should be using wp_reset_postdata()

  • It seems you are trying to add your pagination on top of your query. In order for this to work, you need to define your custom query first. You can add your pagination before the loop however.

  • As I said, you need to set the $max_pages parameter in next_posts_link()

Your query should look similar to this

$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$args = array(
    'paged' => $paged,
    //Rest of your arguments
);
$loop = new WP_Query( $args );

/*
 * If you need your pagination above the loop,
 * this is the earliest to add it. You cannot add it above
 */
next_posts_link( 'Next Posts', $loop->max_num_pages );
previous_posts_link( 'Previous Posts' );

if ( $loop->have_posts() ) {
    while ( $loop->have_posts() ) {
    $loop->the_post();

        //YOUR LOOP

    } // endwhile

    // Add pagination here
    next_posts_link( 'Next Posts', $loop->max_num_pages );
    previous_posts_link( 'Previous Posts' );
    // Reset postdata, VERY VERY IMPORTANT
    wp_reset_postdata();
} // endif

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