-1

I have tried the following answer to randomize post published date: Update existing post dates to random dates

It worked but I need to randomize custom post type. How do I do that? Example: post_type=portfolio

Thank you!

  • $posts = get_posts( array( 'numberposts' => -1, 'post_status' => 'any', 'post_type' => 'portfolio' ) ); ? – kero Sep 20 '18 at 16:15
  • 1
    @kero can you post answers as answers? Comments are for clarifying questions – Tom J Nowell Sep 20 '18 at 16:31
0

You can specify the argument post_type for the function get_posts() (see all available arguments here). So this line

$posts = get_posts( array( 'numberposts' => -1, 'post_status' => 'any' ) );

will become this line

$posts = get_posts( array( 'numberposts' => -1, 'post_status' => 'any', 'post_type' => 'portfolio' ) );

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.