0

How Do I get the ID of latest 10 pages from a certain category in my wordpress blog. Please suggest me a relevant function to get that in a form f array or something that could give me the ID's of latest 10 pages of my blog.

2
  • Do you mean get the latest 10 posts from a category? – KC Chai May 16 '15 at 6:59
  • no I mean latest 10 pages from a category. My wordpress blog has Page Categories as well. – Sarita Mahar May 16 '15 at 7:19
2

Try the code below. This is the Reference: WP_Query

<?php

$args = array(
    'post_type' => 'page',
    'posts_per_page' => 10,
    'category_name' => 'mycat',
    'fields' => 'ids'
);
$data = get_posts($args);
print_r($data);                           
3
  • Remember, cat takes an integer value, not the category slug – Pieter Goosen May 16 '15 at 7:40
  • Sorry, my mistake. edited the code – KC Chai May 16 '15 at 7:41
  • 3
    I have changed your code a bit to use the fields parameter to just return an array of ids. This is way faster, and is exactly what the OP wants. Please check my edit. Also, if a parameter is set to default value, you don't need to write it out. It wastes space and time :-) – Pieter Goosen May 16 '15 at 8:03
0

please try this for latest pages.

<?php
    $args = array(
    'post_type' => 'page',
    'posts_per_page' => 10,
    'category'         => '',
    'orderby'          => 'date',
    'order'            => 'DESC',
);
$data = get_posts($args);
print_r($data); ?>

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.