I have this SELECT query and i’m trying to select all posts except the ones which have a certain excerpt. Is it possible?
SELECT p.ID FROM wp_posts AS p WHERE p.post_date > '2013-09-23 09:37:37' AND p.post_type = 'portfolio' AND p.post_excerpt != 'link' AND p.post_status = 'publish' ORDER BY p.post_date ASC LIMIT 1
So i basically want to select a post which has any excerpt than “link”. Obviously it doesn’t work.. It works with the equal sign, but i don’t know how to test against something..
AND p.post_excerpt NOT LIKE ‘ link ‘
inside the quotes : link
forum removes this symbol %
You should try this:
SELECT p.ID FROM wp_posts AS p WHERE p.post_date > '2013-09-23 09:37:37' AND p.post_type = 'portfolio' AND p.post_excerpt NOT like '%link%' AND p.post_status = 'publish' ORDER BY p.post_date ASC LIMIT 1
What version of MySQL are you using? 5.1+ should suppport
!= if it does not, try this
Just forgot to say. I guess NOT LIKE is better for looking in excerpt which is a MEMO type but if you want to use against operator, you should use
Haha! @audemedia and @crossroad said what is needed before me. My posts where both useless
@imangm: All of your posts are very useful, as you are one of most helpful person around.
Hey guys, thanks a lot for your help, i’ve gone with NOT like and it works. However, i had to remove the percentages, otherwise it didn’t work.
My query is like this:
... AND p.post_excerpt NOT like 'link' AND ...
Does it matter that i don’t have the ”%” sign? Will it affect other users?