Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If anyone has a clean solution, please chime in. For now I'm just going to use WordPress's built in DB connection and grab them manually.</p> <p>For the curious...I just threw this together quick...probably not the best..</p> <pre><code>/** * get_wpdb_values() * * DESC: * * Allows you to make a WP Database connection * and return an Array =&gt; Object of what ever * values you need from a table. * * Was made for the purpose of returning a page * list, but since you pass it the field you * want returned, along with with optional filters * it can easily be used for other purposes. * * USAGE: * * array get_wpdb_values ( string $table [, string $field [, array $filters ]] ) * * PARAMETERS: * * ----------|----------------------------------------------------------------- * $table | Required table you want to return values from. * | DO NOT INCLUDE THE WP PREFIX! (e.g. use 'posts' not 'wp_posts' * ----------|----------------------------------------------------------------- * $field | Optional field name you want returned. (Default returns * all) * ----------|----------------------------------------------------------------- * $filters | Optional filtering passed as field =&gt; value array. * ----------|----------------------------------------------------------------- */ function get_wpdb_values( $table = null, $field = "*", $filters = null ) { // Get access to the // WordPress Database // class in this scope global $wpdb; // If we weren't passed any // arguments, get out quick if(is_null($table) || empty($table)) return false; // Add optional filters if // they were passed in if(!is_null($filters)) { // Counter is so we can tell // if there is more then one // filter so we can add the // AND separator in the // SQL query $WHERE = "WHERE "; $counter = 0; foreach ($filters as $key =&gt; &amp;$value) { $counter++; // If we're on the second or more // pair, we add the AND to chain // conditional WHERE's $AND = ($counter &gt;= 2) ? " AND" : null; // Append to existing WHERE // statement $WHERE .= "$AND $key = '$value' "; } } else { // No filters passed $WHERE = null; } // Get WordPress formatted // table name $wp_table = $wpdb-&gt;$table; // Putting it all together $query = "SELECT $field FROM $wp_table $WHERE "; // Make actual DB call // through the built in // MySQL interface for // WordPress to at least // attempt to remain // compatible with mainline return $wpdb-&gt;get_results($query); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload