'How do i remove pages from a php snippet CODE

I used a plugin called "Insert PHP Code Snippet" to create this page:

URL; https://sololoaded.com/All-Profiles/

Snippet Short Code; [xyz-ips snippet="All-Profiles"]

I later find out that most of my pages are appearing inside the page

for a exmaple:

DMCA PAGE

About Us page

please help I need a code on how to remove these pages from appearing inside the snippet page:

Here is the code:

<!-- query -->

<!-- query -->
<?php


add_action('admin_init', function () {
    // Redirect any user trying to access comments page
    global $pagenow;
    
    if ($pagenow === 'edit-comments.php') {
        wp_redirect(admin_url());
        exit;
    }

    // Remove comments metabox from dashboard
    remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');

    // Disable support for comments and trackbacks in post types
    foreach (get_post_types() as $post_type) {
        if (post_type_supports($post_type, 'comments')) {
            remove_post_type_support($post_type, 'comments');
            remove_post_type_support($post_type, 'trackbacks');
        }
    }
});

// Close comments on the front-end
add_filter('comments_open', '__return_false', 20, 2);
add_filter('pings_open', '__return_false', 20, 2);

// Hide existing comments
add_filter('comments_array', '__return_empty_array', 10, 2);

// Remove comments page in menu
add_action('admin_menu', function () {
    remove_menu_page('edit-comments.php');
});

// Remove comments links from admin bar
add_action('init', function () {
    if (is_admin_bar_showing()) {
        remove_action('admin_bar_menu', 'wp_admin_bar_comments_menu', 60);
    }
});

     global $post;
$post_slug=$post->post_name;
    
    $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
    $query = new WP_Query( array(
       
        'post_type' => array( 'page' ),
         'post__not_in' => array(3,5550,8, 73, 6, 11, 9817,22177), 
        'posts_per_page' => 19,
'orderby' => 'title',
    'order'   => 'ASC',
        'paged' => $paged
    ) );
     
?>

<?php if ( $query->have_posts() ) : ?>
<section class="top-stories section-theme-border">
<!-- begin loop -->



                     
                        
                        
                        
<div style="background:white; padding:15px; border-radius: 5px;">
   <div class="row row-lg">                     
                    
                <?php while ( $query->have_posts() ) : $query->the_post(); 


    
$url1 = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail' );
$url2 = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium'); 

    $image_id = get_post_thumbnail_id();
$img_src = wp_get_attachment_image_url( $image_id, 'large' );
$img_srcset = wp_get_attachment_image_srcset( $image_id, 'full' );
$img_alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
?>  
<div class="col-xs-4 col-sm-4 col-md-3">
                <div class="item">
                    <div class="item-media rounded ">
                        <a href="<?php the_permalink(); ?>"
                           class="item-media-content"
                           style="background-image: url('<?php echo esc_attr( $img_src ); ?>');"></a>
                    </div>
                    <div class="item-info text-center">
                        <div class="post-title a item-title text-ellipsis">
                            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                            
                        </div>
                    </div>
                </div>
            </div>
    


<?php endwhile; ?>
    </div></div>
<!-- end loop -->




<div class="container-wrapper songs-pag">
    <?php 
        echo paginate_links( array(
            'base'         => str_replace( 999999999, '%#%', esc_url( get_pagenum_link( 999999999 ) ) ),
            'total'        => $query->max_num_pages,
            'current'      => max( 1, get_query_var( 'paged' ) ),
            'format'       => '?paged=%#%',
            'show_all'     => false,
            'type'         => 'plain',
            'end_size'     => 2,
            'mid_size'     => 1,
            'prev_next'    => true,
            'prev_text'    => sprintf( '<i></i> %1$s', __( 'Previous', 'text-domain' ) ),
            'next_text'    => sprintf( '%1$s <i></i>', __( 'Next', 'text-domain' ) ),
            'add_args'     => false,
            'add_fragment' => '',
        ) );
    ?>
</div>

    </section> 

<?php wp_reset_postdata(); ?>

<?php else : ?>

<?php endif; ?>


Solution 1:[1]

As I observe you have problem in below loop and specifically in funcions the_permalink() and the_title() that is why you are getting all other details as well, so check first than you get it.

                <?php while ( $query->have_posts() ) : $query->the_post(); 


    
$url1 = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'thumbnail' );
$url2 = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium'); 

    $image_id = get_post_thumbnail_id();
$img_src = wp_get_attachment_image_url( $image_id, 'large' );
$img_srcset = wp_get_attachment_image_srcset( $image_id, 'full' );
$img_alt = get_post_meta( $image_id, '_wp_attachment_image_alt', true );
?>  
<div class="col-xs-4 col-sm-4 col-md-3">
                <div class="item">
                    <div class="item-media rounded ">
                        <a href="<?php the_permalink(); ?>"
                           class="item-media-content"
                           style="background-image: url('<?php echo esc_attr( $img_src ); ?>');"></a>
                    </div>
                    <div class="item-info text-center">
                        <div class="post-title a item-title text-ellipsis">
                            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                            
                        </div>
                    </div>
                </div>
            </div>
    


<?php endwhile; ?>
    </div></div>
<!-- end loop -->

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 pradeep