Skip to main content
improve code formatting
Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

How to display related posts according to Title and Category on a WordPress single page?

Here is my code:

    <?php 
$args = array(                          
        'category__in' => $cat_id, // OK
            'posts_per_page' => 6,
            'post__not_in'   => array( get_the_ID() ),
            );
                
    $wpex_query = new wp_query( $args );
?>
<?php 
$args = array(                          
    'category__in'   => $cat_id, // OK
    'posts_per_page' => 6,
    'post__not_in'   => array( get_the_ID() ),
);
                    
$wpex_query = new WP_Query( $args );
?>

Note: Using category in query is OK. But I also want the Title in the query.

How to display related posts according to Title and Category on a WordPress single page?

Here is my code:

    <?php 
$args = array(                          
        'category__in' => $cat_id, // OK
            'posts_per_page' => 6,
            'post__not_in'   => array( get_the_ID() ),
            );
                
    $wpex_query = new wp_query( $args );
?>

Note: Using category in query is OK. But I also want the Title in the query.

How to display related posts according to Title and Category on a WordPress single page?

Here is my code:

<?php 
$args = array(                          
    'category__in'   => $cat_id, // OK
    'posts_per_page' => 6,
    'post__not_in'   => array( get_the_ID() ),
);
                    
$wpex_query = new WP_Query( $args );
?>

Note: Using category in query is OK. But I also want the Title in the query.

Source Link

WordPress Related Posts by Title and Category

How to display related posts according to Title and Category on a WordPress single page?

Here is my code:

    <?php 
$args = array(                          
        'category__in' => $cat_id, // OK
            'posts_per_page' => 6,
            'post__not_in'   => array( get_the_ID() ),
            );
                
    $wpex_query = new wp_query( $args );
?>

Note: Using category in query is OK. But I also want the Title in the query.