Need Help with Custom Query
-
I have a page (article.php) that is outside the loop, the theme, in fact it’s sitting on the root. I am trying to pass to it some variables (post_title and perhaps ID) from my last 3 posts with the “News” category. Another page reads from article.php. Here is an example of what I need to print to this page…….
<?php print "{articles : [ {id: 1, title : \"Post Title 1\", picture : \"large/1.jpg\", thumb : \"small/1.jpg\"}, {id : 2, title : \"Post Title 2\", picture : \"large/2.jpg\", thumb : \"small/2.jpg\"}, {id : 3, title : \"Post Title 3\", picture : \"large/3.jpg\", thumb : \"small/3.jpg\"} ]}"; ?>
Here is the query and script I have been trying to run to get it to output the above….
<?php include_once('wp-config.php'); include_once('wp-includes/wp-db.php'); $query = $wpdb->get_results("SELECT * FROM $wpdb->wp_posts, $wpdb->wp_post2cat WHERE ID = post_id AND category_id = 7"); print "{articles : ["; $num=1; while ($results = mysql_fetch_object($query)) { print "{id : ".$results->ID.", title : \"".$results->post_title."\", picture : \"large/".$num.".jpg\", thumb : \"small/".$num.".jpg\"}"; $num++; } print "]}"; ?>
Hoping someone can help me figure this out. Thanks in advance!
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Need Help with Custom Query’ is closed to new replies.