queries, arrays, and results >> for dummies
-
I need help figuring out how to fetch the desired values from arrays when a query is performed. For example, I need to display $wpdb->terms.name (associated with post) of tags where $wpdb->term_taxonomy.name = ‘comment_tag’. (See code below) I get the term_id numbers…but I want the term names to be displayed. Basically, even after experimenting with various template tags and functions, I still don’t know how to fetch the desired values. When it comes to queries, I don’t really know whether I should be using get_results or get_col. Is there a good beginners resource for learning how to fetch and display desired wpdb data using queries and arrays? A simple beginners guide/tutorial would be quite handy. I’ve spent many unsuccessful hours trying to figure this out, so any help here is very much appreciated!
Both of these examples return results of term_ID numbers…but what I need is the term names to be displayed in json_encode format such as [“termname1”, “termname2”]. In my testing scenario, the term name for #24 is green and term name for #25 is blue. [“blue”,”green”] is the result I want. So even if there is not a way to display term names with a single query, there must be a way to take the term_ID numbers from one query (i.e. 24,25) and use them fetch the term names using another query. Right?
EXAMPLE 1: The result is [“24″,”25”]
$tagquery = get_the_category(" SELECT $wpdb->name FROM $wpdb->terms WHERE $wpdb->tt.taxonomy = 'comment_tag' ORDER BY name ASC"); $tagdisplay = $wpdb->get_col($tagquery['name']); echo json_encode($tagdisplay);
EXAMPLE 2: Gets same result as above… [“24″,”25”]
$tagquery = get_object_taxonomies('post'); $tagdisplay = $wpdb->get_col($tagquery['name']); echo json_encode($tagdisplay);
- The topic ‘queries, arrays, and results >> for dummies’ is closed to new replies.