2

I'm working on carousel slider plugin. So far so good! But i want the user to be able to select which post type the slider must slide.

Wordpress does have a function called: get_post_types( $args, $output, $operator);

But this function has an argument called '_builtin' (bool). True returns all standard wordpress post_types like 'post, 'page' and 'attachement'. False returns all custom post types.

What I want is to return both.

    public function post_type() {
        $args = array( 
            'public'    => true,
            '_builtin'  => true or false // I want this to return both true and false
        );

        $get_post_types = get_post_types( $args, 'names', $output);

        return $get_post_types;
        //var_dump($get_post_types);
    }

Actual Question

Is there some kind of workaround so i can select both true and false or is it recommended to write my own custom wpdb query? Or is there some kind of method to select true and false?

p.s. i use this function in a class so that explains the "public" keyword

2
  • 4
    have you tried with empty args : get_post_types([], "names") ?
    – mmm
    Aug 1, 2016 at 19:49
  • @mmm , Tried it and it worked! Thanks a lot it cost me 2 hours to figure this out.
    – Paul
    Aug 1, 2016 at 19:56

1 Answer 1

2

Thanks to @mmm

The solution in this case is pretty simple. Just pass an empty $args array. Then it neglects the default '_builtin'

Example

$get_post_types = get_post_types( $args = array(), $output, $operator );
return $get_post_types;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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