3804 posts
  • Elite Author
  • Author Level 11
  • Trendsetter
  • 7 Years of Membership
+12 more
KrownThemes
says

Hello all

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..

25 posts
  • Trendsetter
  • Elite Author
  • Author Level 7
  • Exclusive Author
+5 more
audemedia
says

AND p.post_excerpt NOT LIKE ‘ link ‘

25 posts
  • Trendsetter
  • Elite Author
  • Author Level 7
  • Exclusive Author
+5 more
audemedia
says

inside the quotes : link

forum removes this symbol % :-(

1891 posts The Last Man Standing
  • Weekly Top Seller
  • Author Level 8
  • Beta Tester
  • Moderator
+10 more
ImanGM
Moderator
says

Hey!

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
313 posts
  • 3 Years of Membership
  • Exclusive Author
crossroad
says

What version of MySQL are you using? 5.1+ should suppport != if it does not, try this <>

1891 posts The Last Man Standing
  • Weekly Top Seller
  • Author Level 8
  • Beta Tester
  • Moderator
+10 more
ImanGM
Moderator
says

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 <> not !=

Cheers,
Iman

1891 posts The Last Man Standing
  • Weekly Top Seller
  • Author Level 8
  • Beta Tester
  • Moderator
+10 more
ImanGM
Moderator
says

Haha! @audemedia and @crossroad said what is needed before me. My posts where both useless :D

313 posts
  • 3 Years of Membership
  • Exclusive Author
crossroad
says

@imangm: All of your posts are very useful, as you are one of most helpful person around.

1891 posts The Last Man Standing
  • Weekly Top Seller
  • Author Level 8
  • Beta Tester
  • Moderator
+10 more
ImanGM
Moderator
says

@imangm: All of your posts are very useful, as you are one of most helpful person around.

My pleasure :sunglasses:

3804 posts
  • Elite Author
  • Author Level 11
  • Trendsetter
  • 7 Years of Membership
+12 more
KrownThemes
says

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?

by
by
by
by
by
by