Padawan
Padawan

Reputation: 51

mysql query wp_post list and category and date

I need to get a list of all post from one category and since some date until today.

The problem is that i dont find a way to ask this to google & im starting using mysql...

I think that it will be something like:

SELECT * FROM `wp_posts` WHERE 1  and the rest...

Upvotes: 0

Views: 114

Answers (1)

MatejG
MatejG

Reputation: 1423

Use wordpress built in function to get posts

<?php $args = array(
    'posts_per_page'   => 5,
    'offset'           => 0,
    'category'         => '',
    'category_name'    => '',
    'orderby'          => 'post_date',
    'order'            => 'DESC',
    'include'          => '',
    'exclude'          => '',
    'meta_key'         => '',
    'meta_value'       => '',
    'post_type'        => 'post',
    'post_mime_type'   => '',
    'post_parent'      => '',
    'post_status'      => 'publish',
    'suppress_filters' => true 
);
$posts_array = get_posts( $args ); ?>

If you need to get it from date till now, use class "WP_Query":

$args = array(
    'date_query' => array(
        array(
            'after'     => array(
                'year'  => 2015,
                'month' => 1,
                'day'   => 31,
            ),
            'inclusive' => true,
        ),
    ),
    'category_name'    => 'category',
    'posts_per_page' => -1,
);
$query = new WP_Query( $args );

This should give you clue where to continue. For more detailed examples follow Wordpress codex: http://codex.wordpress.org/Class_Reference/WP_Query

Upvotes: 1

Related Questions