0

I need an array that contains all the posts names that match with the post_type"pelicula"

1
<?php // query for your post type
    $post_type_query  = new WP_Query(  
        array (  
            'post_type'      => 'pelicula',  
            'posts_per_page' => -1
        )  
    );   
    // we need the array of posts
    $posts_array      = $post_type_query->posts;   
    // create a list with needed information
    // the key equals the ID, the value is the post_title
    $post_title_array = wp_list_pluck( $posts_array, 'post_title', 'ID' );
    var_dump($post_title_array);
    ?>
1

Use get_posts( $args ) that uses WP_query($args) to create an array of posts.

$posts_array = get_posts( 'post_type' => 'pelicula', 'posts_per_page' => -1 );

$post_title_array = wp_list_pluck( $posts_array, 'post_title', 'ID' );

Note: post_name is the unique slug for the post and post_title refers to the Title of the post. So you may adjust above code accordingly.

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.