Getting posts from wordpress returns the same result when present in several cathegories
In the home page of a website I need to return the last 3 posts of the blog, created with wordpress.
I have this code:
SELECT p.post_title, p.post_date, p.post_content, wpr.object_id, dt_blog_terms.name, dt_blog_terms.slug
INNER JOIN dt_blog_term_taxonomy ON dt_blog_terms.term_id = dt_blog_term_taxonomy.term_id
INNER JOIN dt_blog_term_relationships wpr ON wpr.term_taxonomy_id = dt_blog_term_taxonomy.term_taxonomy_id
INNER JOIN dt_blog_posts p ON p.ID = wpr.object_id
WHERE taxonomy = 'category'
AND p.post_type = 'post'
AND p.post_status = 'publish'
AND slug != 'notizie-notifiche'
ORDER BY `post_date` DESC
As you can see, I have one cathegory (notizie-notifiche) that I want to exclude. This sql string works, but I have a problem when the post has more than one cathegory. In this case, it is returned once for every cathegory, while I want to show it only once in total.
I thought I could use DISTINCT, but it does not seem to work with this kind of SELECT statement.
I can tell you what you need to do, but I can't modify the query to do it. You use the term "category" in your question, but there is no field by that name in your data.
You need to aggregate your data, at the level you want, and then include a
having clause. The following
group by may solve your problem:
group by p.id
having sum(case when slug = 'notizie-notifiche' then 1 else 0 end) = 0
Custom posts listing widget always returns 1 extra result
I've built my own custom 'recent posts' widget to display some more content than the default core WP recent posts widget does. I'm struggling with controlling my list of entries. Currently, the widget always returns 1 additional post to the list selected. So if I select 1 post to show, it will actually show 2, and so forth. I'm not really sure wher...
get_next_posts_link() returns no result despite available posts
I am developing a custom theme based on the Genesis framework. I want to display a 'previous post | next post' navigation below any article in the single post view. However, neither get_next_posts_link() nor get_previous_posts_link() return any value. All output I can see is | Of course, there are adjacent posts available. My code looks something l...
Running several WordPress sites on same core / plugins?
Is it possible to run more than one site on the same WordPress core and a set of plugins? I want to be able to have custom plugins and themes for each site, but have a base set that is the same, to make it easier to maintain.
WordPress - Several Menulinks to same URL active
Im designing a big Dropdown-Menu with 2 Sub-Levels in the Divi WordPress Theme, where several menu-links are individual-links pointing to the same Page (the customer wants this). Now all of those links get an active class by default in WordPress once any link is clicked. Is there an easy way around this without using jQuery? I tried solving this us...
Widget with same content across several websites
I'm managing a couple of websites from the same client. They have lots of partners and have a logo slider on the bottom of each page across 5 websites. The partners change from time to time and the content manager has to update the logos on 5 sites separately. Maybe there's a way so that you can change the logos one time and the other sites change ...