I have a fairly complex need, which I am not entirely certain of where to start due to my somewhat limited knowledge of WordPress's database structure and everything.. So here's what I have going on.
I have a custom table that would look something like this:
wp_buzzsumo
+--------------------------------------+
| id pageID title totalShares date |
+--------------------------------------+
| 1 25 - 20000 - |
| 2 29 - 1992 - |
| 3 25 - 122345 - |
| 4 27 - 134 - |
+--------------------------------------+
I have a WordPress query that looks like this:
SELECT * FROM wp_buzzsumo ORDER BY totalShares DESC LIMIT 20
And then in the loop in PHP where I output the results, I have some statements to check some things.. But now due to the LIMIT
of 20
in some cases it does not return anything because the top 20 results fail the if statements... So now I need a way to put these statements into the query..
if(
!get_field("hide_trending_bar", $PageID) &&
!get_field("hide_hashtags_from_trending_bar", $PageID) &&
get_page($PageID)->post_status == "publish"
)
$PageID would have to match the pageID
column in the table above.
I need a query something like this I believe.. But I know this isn't quite the right way of doing this..
SELECT * FROM wp_buzzsumo
WHERE wp_posts.pageID=wp_buzzsumo.pageID
AND wp_posts.post_status = 'publish'
AND (
wp_posts.meta_key = 'hide_trending_bar'
AND
wp_posts.meta_value = ""
)
AND (
wp_posts.meta_key = 'hide_hashtags_from_trending_bar'
AND
wp_posts.meta_value = ""
)
ORDER BY totalShares DESC LIMIT 20