I want to add string array to this function to filter displayed option in drpodown

WordPress wpallimport plugin This filter allows modifying the option shown in the options type dropdown for import

The function is as follow: I want to add $custom_types as string array.

function wpai_custom_types( $custom_types ) {   

   // Modify the custom types to be shown on Step 1.
    $custom_types = array("woocommerce orders" , " posts")
   // Return the updated list. 
   return $custom_types;

}
add_filter( 'pmxi_custom_types', 'wpai_custom_types', 10, 1 );

But it won’t work

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

WooCommerce Orders are registered as shop_order not “woocommerce orders”. Also you have a space in ” posts”.

Try:

$custom_types = array("shop_order" , "post");

Posts aren’t custom post types in WordPress though. They’re of the default post types that are registered in WP.

Method 2

For posts & products:

add_filter( 'pmxi_custom_types', 'example_import_show_only_posts_and_products', 10, 2 );

function example_import_show_only_posts_and_products ($custom_types, $type = '') {
    
    global $wpdb;
    
    $new_types = array();
    
    foreach ($custom_types as $post_key => $post_obj) {
        if ( $post_key == 'post' || $post_key == 'product' ) {
            $new_types[$post_key] = $post_obj;
        }
    }
    
    return $new_types;
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x