Show most tagged taxonomy terms - wordpress

I'm trying to achieve a list of most tagged taxonomy tagged in last 24 hours. For an instance:
China from taxonomy country has been tagged 20 times
Eminem from taxonomy music has been tagged 15 times
Chelsea from taxonomy football has been tagged 10 times
USA from taxonomy country has been tagged 12 times
The result should show list something like: China Eminem USA Chelsea
I ended up with this:
<?php $terms = get_terms( array(
'taxonomy' => 'country','music','football',
'orderby' => 'count',
'monthnum' => date('m'),
'day' => date('d'),
'year' => date('Y')
);
$loop = new WP_Query($args);
if ($loop->have_posts()) :
while ($loop->have_posts()) : $loop->the_post(); ?>

Related

How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?

I have a CPT with daily deals, I need to show these daily deals on my frontend as per today's day.
For eg, if it is Thursday : The returning array should return Thursday, Friday, Saturday, Sunday, Monday, Tuesday, Wednesday.
For this to happen I have a meta_value on all posts namely Day which returns days in the following order:
$days = [
1 => 'Monday',
2 => 'Tuesday',
3 => 'Wednesday',
4 => 'Thursday',
5 => 'Friday',
6 => 'Saturday',
7 => 'Sunday',
];
My current WP_Query is follows which returns data in ascending order according to date : Monday to Sunday
$args = array(
'post_status' => 'publish',
'post_type' => 'special',
'meta_key' => 'day',
'orderby' => 'day',
'order' => 'ASC',
);
I want to construct a query such as I can assign a starting day and then continue the rest of the days.
Could anyone please help?
I tried adding comparing operators but they just remove the rest of the days as a whole.

get posts from specific category, but not belongs any other category

Let's say I have category Ids 100,101 & 102
I have following posts
post A belongs to category 101 & 102
post B belongs to category 101
post C belongs to category 100,101 & 102
post D belongs to category 100 & 102
post E belongs to category 101
And my logic is to get posts belongs to category 101, but not falls under any other category.
So the results set should be post B & post E only.
I tried following options which is giving me same results;
$query = new WP_Query( array( 'cat' => 101 ) );
$query = new WP_Query( array( 'category__in' => 101 ) );
Both above queries are giving me post A,post B,post C & post E. But I want only post B & post E.
How can I achieve that with WP_Query ?

WP_Query orderby multiple parameters not working

I am trying to sort by my WP_Query results by two meta fields, first date and then time. So effectively
Date A 17:00
Date B 18:00
Date C 07:00
Date B 10:00
Date A 9:00
would be come
Date A 9:00
Date A 17:00
Date B 10:00
Date B 18:00
Date C 07:00
This is my current code:
"post_type" => "event",
"post_status" => "publish",
"posts_per_page" => 25,
"ignore_sticky_posts" => 0,
"show_sticky" => true,
"meta_query" => array(
array(
"key" => "_meta_event_start_date",
"compare" => ">=",
"value" => 0
),
array(
"key" => "_meta_event_start_time",
"compare" => ">=",
"value" => 0
),
),
"order" => "ASC",
"orderby" => "_meta_event_start_date _meta_event_start_time"
It is currently sorting my results appropriately by the date, but not the time (time format is stored hh:mm (24hr)). How might I amend the query to make this work?
I have seen other responses recommending using foreach loops, sql queries or even filters. I can't use these unfortunately as the site I'm working on uses the search plugin Facet WP, and as search requires WP_Query to query the database and output content.
Thanks in advance.
As I see you are trying to order by meta keys - you have to use in this case a quite more complicated syntax according to changes in WordPress 4.2 - something like below:
"post_type" => "event",
"post_status" => "publish",
"posts_per_page" => 25,
"ignore_sticky_posts" => 0,
"show_sticky" => true,
"meta_query" => array(
"event_start_date" => array(
"key" => "_meta_event_start_date",
"compare" => ">=",
"value" => 0
),
"event_start_time" => array(
"key" => "_meta_event_start_time",
"compare" => ">=",
"value" => 0
)
),
"orderby" => array(
"event_start_date" => "ASC",
"event_start_time" => "ASC"
)
Additionally - for single meta_key ordering it is worth to remember that you have to use in the orderby clause values meta_value and meta_value_num

Filter results of get_terms() in wordpress

I am displaying a list of faculty members with some custom field information from a custom taxonomy called "faculty-members". The name of each term is the full name of the faculty member, so when I order by name using get_terms(), I get an alphabetical list based on first name. I know I can filter get_terms(). but I can't figure out if there is any way I can filter my array of returned objects so that it picks up the last name from the name field and sorts it that way? As always, any help would be greatly appreciated.
For reference, this is what the first two returned objects look like
Array ( [0] => stdClass Object ( [term_id] => 44 [name] => Abigail McKenzie [slug] => abigail-mckenzie [term_group] => 0 [term_taxonomy_id] => 47 [taxonomy] => faculty-member [description] => Abigail McKenzie has a BFA in painting from the Cleveland Institute of Art, and an MA and MFA in printmaking from the University of Iowa. She is currently the chairman of the Art Department at Flint Hill School in Oakton, Virginia. [parent] => 0 [count] => 1 ) [1] => stdClass Object ( [term_id] => 7 [name] => Amanda Dalla Villa Adams [slug] => amanda-dalla-villa-adams [term_group] => 0 [term_taxonomy_id] => 10 [taxonomy] => faculty-member [description] => Amanda Dalla Villa Adams is a current doctoral student in art history at Virginia Commonwealth University, received her BFA in sculpture from VCU, and her MA in art history from the University of Cincinnati. [parent] => 0 [count] => 3 )

Having an issue doing a WP_Query with post_content and category__and

This is the array for my arguments for the WP_Query.
Array
(
[showposts] => 4
[paged] => 1
[post_type] => post
[post_content] => tree
[category__and] => Array
(
[0] => 6
[1] => 15
[2] => 28
)
)
I want to return the posts where they are in the categories 6, 15, 28 and where the post_content has the word tree.
My problem is that I'm returning several duplicated results for the posts that have the word tree in it. Ideally I would like to return one.
anyone have any idea how I can fix or improve this?
I found the issue, I shouldn't have been trying to filter on post_content, but rather 's'
e.g.
Array
(
[showposts] => 4
[paged] => 1
[s] => post
[post_content] => tree
[category__and] => Array
(
[0] => 6
[1] => 15
[2] => 28
)
)

Resources