0

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();
?>
1
  • Define 'weird'. Also, this is sort of what the categories/taxonomies are for. You could categorize your posts and then within a page you could link a taxonomy to each page using a custom field. Then just run a standard query using that custom field. And also, shouldn't you have a % before and after the $str? Like so LIKE '%".$str."%'. Jan 27 at 22:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.