Jump to content

Help with confusing query...


bwboard

Recommended Posts

Version: 5.1.33-community-log

 

Code:

SELECT DISTINCT wposts.* 
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta, wp_ratepost_post 
WHERE wposts.ID = wpostmeta.post_id 
AND wp_ratepost_post.post_id = wpostmeta.post_id 
AND wposts.post_status = 'publish' 
AND wposts.post_type = 'post' 
AND wposts.post_status = 'publish' 
ORDER BY wp_ratepost_post.avg_vote DESC 

 

Structure:

CREATE TABLE `wp_posts` (
`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`post_author` bigint(20) NOT NULL DEFAULT '0',
`post_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`post_date_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`post_content` longtext NOT NULL,
`post_title` text NOT NULL,
`post_category` int(4) NOT NULL DEFAULT '0',
`post_excerpt` text NOT NULL,
`post_status` varchar(20) NOT NULL DEFAULT 'publish',
`comment_status` varchar(20) NOT NULL DEFAULT 'open',
`ping_status` varchar(20) NOT NULL DEFAULT 'open',
`post_password` varchar(20) NOT NULL DEFAULT '',
`post_name` varchar(200) NOT NULL DEFAULT '',
`to_ping` text NOT NULL,
`pinged` text NOT NULL,
`post_modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`post_modified_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`post_content_filtered` text NOT NULL,
`post_parent` bigint(20) NOT NULL DEFAULT '0',
`guid` varchar(255) NOT NULL DEFAULT '',
`menu_order` int(11) NOT NULL DEFAULT '0',
`post_type` varchar(20) NOT NULL DEFAULT 'post',
`post_mime_type` varchar(100) NOT NULL DEFAULT '',
`comment_count` bigint(20) NOT NULL DEFAULT '0',
PRIMARY KEY (`ID`),
KEY `post_name` (`post_name`),
KEY `type_status_date` (`post_type`,`post_status`,`post_date`,`ID`),
KEY `post_parent` (`post_parent`)
) ENGINE=MyISAM AUTO_INCREMENT=91 DEFAULT CHARSET=utf8

CREATE TABLE `wp_ratepost_post` (
`post_id` int(11) NOT NULL,
`avg_vote` double(3,2) NOT NULL,
`count` int(6) NOT NULL,
PRIMARY KEY (`post_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8

 

 

I'm attempting to get all posts and their relevant information from wp_posts and order them by their avg_vote. I've managed to get it to output something, but not all of the posts have ratings, so i need it to still show them but below all of the rated posts.

Link to comment
Share on other sites

SELECT DISTINCT wposts.*
FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
INNER JOIN `wp_ratepost_post` wratepost ON wratepost.post_id = wpostmeta.post_id
WHERE wposts.ID = wpostmeta.post_id
AND wposts.post_status = 'publish'
AND wposts.post_type = 'post'
AND wposts.post_status = 'publish'
ORDER BY wratepost.avg_vote DESC 

 

?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.