Woocommerce show products featured by sql category

Asked

Viewed 95 times

0

would like this result to be just 1 with all formations separated by column

and that it only appears if there is name = 'Resin' AND name = 'featured' otherwise do not list

inserir a descrição da imagem aqui sql

if I put WHERE b.name = 'featured' and b.name = 'Resins' do not return me value

inserir a descrição da imagem aqui

  • name = 'Resina' AND name = 'featured' basically you already have the solution, put this in a where in your query

  • if I do it does not return me result

  • And it’s right he returns nothing

  • he can’t have both names at the same time

  • therefore the use of Union is necessary

  • I need you to list only if the two exist otherwise I don’t want you to list

Show 1 more comment

2 answers

0


Getting to solve staff follows below how to solve

Select *
FROM
(
Select d.ID, d.post_title, d.post_type,
MIN(CASE WHEN b.name = 'Resinas' THEN b.name END) AS categoria, 
MIN(CASE WHEN b.name = 'featured' THEN b.name END) AS destaque
from wp_term_taxonomy a
inner join wp_terms b on a.term_id = b.term_id
inner join wp_term_relationships c on a.term_taxonomy_id = c.term_taxonomy_id
inner join wp_posts d on c.object_id = d.id
where b.name IN ('Resinas', 'featured') and d.post_type = 'product'
GROUP BY d.ID
) AS x
WHERE x.destaque = 'featured' AND x.post_type = 'product' AND x.categoria = 'Resinas'

inserir a descrição da imagem aqui

0

Put your question in a Where clause

Thus:

Select d.ID, a.taxonomy, b.name, d.post_title, d.post_type
from wp_term_taxonomy a

inner join wp_terms b on a.term_id = b.term_id
inner join wp_term_relationships c on a.term_taxonomy_id = c.term_taxonomy_id
inner join wp_post d on c.object_id = d.id

where b.name = "Resina"

union

Select d.ID, a.taxonomy, b.name, d.post_title, d.post_type
from wp_term_taxonomy a

inner join wp_terms b on a.term_id = b.term_id
inner join wp_term_relationships c on a.term_taxonomy_id = c.term_taxonomy_id
inner join wp_post d on c.object_id = d.id

where b.name = "featured"
  • me returned all category values

  • Would be everyone who contains that name or at least somewhere

  • if you want something specific take the like and put equal without the percentage

  • thus : Where b.name = "featured"

  • exact however it needs to contain tmb b.name = 'Resins'

  • yes, add too, apart from the like

  • Already manage to solve and I posted thanks for the help

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.