Warning: in_array() null given in PHP function

Well first you have this code // no matter what the value here, you can forget about it (because in the next line of code you assing a new value to the same variable) $post_types = apply_filters( ‘sortable_wordpress_gallery_post_types’, array( ‘post’ ) ); // only this really matters $post_types = apply_filters( ‘sortable_wordpress_gallery_’ . $this->id . ‘_post_types’, … Read more

How to optimize update_post_meta?

To achieve what you want you’re better creating an associative array and then walking over it with a foreach loop as shown below : $data = array( ‘_shipping_first_name’ => $order->get_billing_first_name(), ‘_shipping_last_name’ => $order->get_billing_last_name(), ‘_shipping_company’ => $order->get_billing_company(), ‘_shipping_address_1’ => $order->get_billing_address_1(), ‘_shipping_address_2’ => $order->get_billing_address_2(), ‘_shipping_postcode’ => $order->get_billing_postcode(), ‘_shipping_city’ => $order->get_billing_city(), ‘_shipping_state’ => $order->get_billing_state(), ‘_shipping_country’ => $order->get_billing_country() ); … Read more

Verify if a category is the child of another category

Yes, there are two functions you can use: For the default category taxonomy, you can use cat_is_ancestor_of(): // Retrieve category object by slug: $parent_cat = get_category_by_slug( ‘clothes’ ); // term object $child_cat = get_category_by_slug( ‘t-shirts’ ); // term object /* Or retrieve category ID by name: $parent_cat = get_cat_ID( ‘Clothes’ ); // term ID $child_cat … Read more

How to update and save user metadata on page visits?

There are lots of actions you can hook into to do this, I think the best once to use would be wp or template_redirect. Using either of those actions the code would be like this, this code goes into the functions.php add_action(‘wp’, ‘bt_update_user_homepage_meta’); function bt_update_user_homepage_meta () { // get user id, if user is not … Read more

WordPress: Custom User Role cannot access Custom Post Type | “Sorry, you are not allowed to access this page”

SOLUTION: With some playing around I realized I am definitely an idiot and WAY over-thought things. While I had previously read and tried some of the things in this similar post, I ended up substituting their code for mine and found it actually worked for my use case. In trying to understand why that was, … Read more