开发者

SQL function for data retrieval JOIN (second attempt)

Trying to write an SQL function that collects data from two different tables. It should get the current post id from wp_posts and then find the corresponding images from a table called wp_postdata.

Table 1

------------------------------           
id   ||   title   ||  content
------------------------------

Table 2

---------------------------------------------------------
meta_id   ||   post_id   ||   meta_key   ||   meta_value
---------------------------------------------------------

The meta_key that we are after is called _wp_attachment_metadata

My failed attempt ::

<?php
$pics = mysql_query("SELECT    id,  
           meta_key_wp_attached_file.meta_value picture 
 FROM      wp_posts
 LEFT JOIN wp_postmeta meta_key_wp_attached_file 
 ON        meta_key_wp_attached_file.post_id = wp_posts.id 
 WHERE     meta_key_wp_attached_file.meta_key = 'picture' 
    ORDER BY picture;");

while ($row = mysql_fetch_array($pics)) {
    $thumb = $row['picture'];
    echo '<img src="http://www.golfb开发者_开发百科rowser.com/wp-content/uploads/'.$thumb.'" />';

}

    ?>

Any ideas,

Marvellous


Should be: meta_key = '_wp_attachment_metadata', and you'll need to unserialize the result.

Or you can use the API:

http://codex.wordpress.org/Function_Reference/WP_Query

http://codex.wordpress.org/Function_Reference/get_post_meta

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜