[resolved] My get_results query not returning any results (2 posts)

  1. colinsp
    Posted 2 years ago #

    Anyone got any clues please? I expect I have done something stupid.

    //Assign users to studies as authors
    global $wpdb;
    echo "Started";
    // First get the profiles
    $result = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE  post_type='name_profile'");
    print_r ($result);
    foreach ($result as $results){
    $study_id = $results->id;
    echo "Study ID= ". $study_id;
    $study_name = $results->post_title;
    echo $study_name;
    /*$result1 = $wpdb->get_row("SELECT * FROM $wpdb->variants WHERE  study = $study_name");
    $author = $result1->number;
    $result2 = $wpdb->get_row("SELECT id FROM $wpdb->users WHERE  user_login = $author");
    $author = $result2->id;
    echo $author;
     $my_post = array(
          'ID'           => $study_id,
          'post_author' => $author
    // Update the post into the database
      wp_update_post( $my_post );*/
    echo "Updated";
  2. Steven Jones
    Posted 2 years ago #

    If you have a specific problem, it's best just to post the code that is relative to it.

    What is returned when you print $result?

    Also, is there any reason you're not using WP_Query to perform this?

Topic Closed

This topic has been closed to new replies.

About this Topic