WordPress.org

Forums

How to run own query with wp_query? (3 posts)

  1. DDT
    Member
    Posted 5 years ago #

    Hi

    I like to get a custom array from a db table to create a table in a page template

    like

    global  $wpdb;
    
      // find list of events
      $qry = "SELECT select event_name, event_link, event_loc, event_desc, event_start_time, event_end_time FROM wp_wplistcal ORDER BY event_start_time ASC";
      $events = $wpdb->get_results( $qry );
    var_dump($events);

    but it just returns array(0) { }

    I know for a fact that the table has values.

    So how can i use own queries in WP??

  2. DDT
    Member
    Posted 5 years ago #

    solved so far.

    i had a double SELECT

  3. nouveller
    Member
    Posted 5 years ago #

    It's because the output of get_results is an object by default.

    Try passing a second argument to make it an associative array.

    $events = $wpdb->get_results($qry, ARRAY_A);

    More info: http://codex.wordpress.org/Function_Reference/wpdb_Class#Examples_5

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags