2

I have solved the main query:

For WordPress dashboard, I needed the list of all posts related to all post types in:

edit.php?post_type=product

Using the concept of:

edit.php?post_type=product&showall=true

With function in backend function.php

function show_all_posttypes( $query ) {
    if( ! is_admin() ) {
         return;
    }

    if( isset( $_GET, $_GET['showall'] ) && true == $_GET['showall'] ) {
        $query->set( 'post_type', array('product', 'second_type_product', 'third_type_product') );
    }   
}

add_filter( 'pre_get_posts', 'show_all_posttypes' );

And after that my all posts related to three post types: product, second_type_product, third_type_product is listing very well on URL:

edit.php?post_type=product&showall=true

But when I am using its feature to filter on edit.php page with all listed posts then is saying:

Invalid post type

I want to achieve every feature support with my list related to multiple post types list on url based on one post type.

Thanks for support!

3
  • 1
    Did you try adding a check for $query->is_main_query()? Commented Oct 18, 2016 at 21:25
  • I think it is one of the thing I need to solve this issue, but not the solution. Commented Oct 19, 2016 at 9:18
  • @brianjohnhanna Just test the code without that check, it works. Commented Oct 20, 2016 at 16:13

3 Answers 3

1

Invalid Post Type might be shown,whenever you have a mistake(type or etc..) in 'product', 'second_type_product', 'third_type_product' . Ensure that you have correct words there.

2
  • I used the code above and a fresh install of wordpress, and it worked just fine. The only issue was that a couple warnings popped up because there are some pieces of edit.php that do not work with an array of post types, tries to print out the array as a string. Otherwise, @tazo's solution should be correct.
    – socki03
    Commented Oct 19, 2016 at 17:07
  • @tazo-todua Just test the code without wrong types included, it works. Commented Oct 20, 2016 at 16:14
0

I would debug it like following:

  • Check where the error is being thrown - This almost for certain in the wp-admin/edit.php file - debug the $post_type variable there
  • Try to set the post type variable in your pre_get_posts query correctly

Furthermore, it would be nice if you could share some code with which I can test your problem.

0

Your code is fine. From the error message and the URL parameters, I can guess there is not CPT product in your install, it would work if you replace use any post types registered (post, page, ...) or added a CPT product (by installing WooCommerce for example).

And by the way, I believe you are replacing all posts listing pages on the dashboard with the same page that lists product, second_type_product and third_type_product. Are you sure this is what you want?

Your Answer

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

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