display related posts based on the PAGE TITLE

Question

could you please help me to correct the code. I need to display related posts based on the PAGE TITLE keywords, so when page (not post) loads it shows title+content and related block of posts underneath.

I have this code but it displays the weird results.

<?php 
    $mypostids = $wpdb->get_col("select ID from $wpdb->posts where post_title LIKE '".$str."%' ");

    $args = array(
        'post__in'=> $mypageids,
        'post_type'=>'post',
        'orderby'=>'title',
        'order'=>'asc',
        'posts_per_page'=>3, 
    );


$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
    _e("");
    while ( $the_query->have_posts() ) {
       $the_query->the_post();
?>

0
rvznsw 1 week 2023-01-21T09:21:21-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse