function be_woocommerce_category_id(){ $categories_array = array(); $categories_array[0] = esc_html__('Choose a Category', 'shopstore'); $args = array( 'orderby' => 'title', 'order' => 'ASC', ); $categories = get_terms( 'product_cat', $args ); if( count($categories) > 0 ){ foreach( $categories as $category ){ $categories_array[$category->term_id] = $category->name; } } return $categories_array; } … [Read more...] about Can’t display product categories on woocommerce getting Invalid taxonomy?
Get_terms returns invalid taxonomy
Why is my working Custom Taxonomy not in get_taxonomies array?
add_action( 'init', 'double_ipa_init' ); function double_ipa_init() { register_taxonomy( 'double-ipa', array ( 0 => 'post', 1 => 'page', ), array( 'hierarchical' => true, 'label' => 'Double IPAs', 'show_ui' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'double-ipa' ), 'singular_label' => 'Double IPA' ) ); } This code is in a plugin, and is on Multisite. … [Read more...] about Why is my working Custom Taxonomy not in get_taxonomies array?
How to remove plugin-specific custom taxonomy terms when plugin is uninstalled?
What I have written mostly works, but the get_terms function returns an 'invalid_taxonomy' error. Looking into it further, I found that the global $wp_taxonomies does not recognize the custom taxonomies created by the plugin during the uninstall.php process. … [Read more...] about How to remove plugin-specific custom taxonomy terms when plugin is uninstalled?
How to Save User Submitted Posts in the Frontend of WordPress
function wpshout_save_post_if_submitted() { // Stop running function if form wasn't submitted if ( !isset($_POST['title']) ) { return; } // Check that the nonce was set and valid if( !wp_verify_nonce($_POST['_wpnonce'], 'wps-frontend-post') ) { echo 'Did not save because your form seemed to be invalid. Sorry'; return; } // Do some minor form validation to make sure there is content if (strlen($_POST['title']) < 3) { echo 'Please enter a title. Titles must be at least three characters long.'; return; } if (strlen($_POST['content']) < 100) { echo 'Please enter content more than 100 characters in length'; return; } // Add the content of the form to $post as an array $post = array( 'post_title' => $_POST['title'], 'post_content' => $_POST['content'], 'post_category' => $_POST['cat'], 'tags_input' => $_POST['post_tags'], 'post_status' => 'draft', // Could be: publish 'post_type' => 'post' // Could be: `page` or your CPT ); wp_insert_post($post); echo … [Read more...] about How to Save User Submitted Posts in the Frontend of WordPress