0

I am trying to access post meta for custom post type and taxonomy using WP_Query and then query the posts with that specific post meta.
So far I have tied the following code:

$hot_args = array(
                            'post_type' => 'video',
                            'posts_per_page' => '6',
                            "order" => "DESC",
                            'meta_key' => 'post_views_count',
                            'orderby' => 'meta_value_num',
                            'date_query'  => array(
                                array(
                                    'after' => '1 week ago'
                                )
                            ),
                            "post__not_in" => $posts__not_in,
                            'tax_query' => array(
                                array(
                                    'taxonomy' => 'video_cat',
                                    'field' => 'slug',
                                    'terms' => "all"
                                )
                            ),
                        );
                        $hot_query = new WP_Query( $hot_args );

This code doesn't work and not returning any results.

For normal posts this piece of code works but for custom post type doesn't, How can I make it work for custom post types?

0

Find The problem ;)
The answer is

$hot_args = array(
                            'post_type' => 'video',
                            'posts_per_page' => '6',
                            "order" => "DESC",
                            'meta_key' => 'post_views_count',
                            'orderby' => 'meta_value_num',
                            'date_query'  => array(
                                array(
                                    'after' => '1 week ago'
                                )
                            ),
                            "post__not_in" => $posts__not_in,
                        );
                        $hot_query = new WP_Query( $hot_args );

There was not video as my custom post type exists in the past week so the there was nothing to return :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.