Dropdown filter in custom posts

When using this hook, your function receives two parameters, onde of them is the slug of the current post_type; <?php function my_post_type_filter($post_type) { $post_slug = $post_type; if( $post_slug == ‘the_post_type_slug’) { // Do something } } add_action( ‘restrict_manage_posts’, ‘my_post_type_filter’ ); ?> To learn more about this hook check the Docs.

wp_dropdown_categories and custom taxonomy + custom post type

You can get your code to work the expected way by adding the following three arguments to your $args array which you pass to wp_dropdown_categories(): name — the select name as in <select name=”<here>”>, and you should set it to theme which is your custom taxonomy slug. value_field — the value of the <option>‘s in … Read more

How do I sort posts with multiple pages

You’re initially submitting a POST request via a form with the sort parameters. When you click links to additional pages, you’re just sending a GET request for the next page without those original POST vars, so they don’t carry over to the additional pages and aren’t picked up by your if(isset($_REQUEST[‘sort’])). Probably the simpler way … Read more

How to use wp_category_checklist()?

Here is the answer I ended up with: $select_cats = wp_dropdown_categories( array( ‘echo’ => 0 ) ); $select_cats = str_replace( “name=”cat” id=”, “name=”cat[]” multiple=”multiple” id=”, $select_cats ); echo $select_cats; It displays a list of my categories that can be multi-selected as per my question. It’s a hack of wp_dropdown_categories, but it works.

get_pages Drop down list for selection of a page

You already have <option value=””>…</option> you just need some extra attrs for it You need to load current value and if value equals $page->ID than add attr selected=”selected” Here’s how it could be done: <select name=”easyreg_redirect_page”> <option selected=”selected” disabled=”disabled” value=””><?php echo esc_attr( __( ‘Select page’ ) ); ?></option> <?php $selected_page = get_option( ‘option_key’ ); $pages … Read more

Remove “Choose An Option” on Product Variation & Auto Select Instead

Following code solves the purpose: add_filter(‘woocommerce_dropdown_variation_attribute_options_args’,’fun_select_default_option’,10,1); function fun_select_default_option( $args) { if(count($args[‘options’]) > 0) //Check the count of available options in dropdown $args[‘selected’] = $args[‘options’][0]; return $args; }

Recreating the hierarchy of taxonomies for a dropdown form menu?

You can use the standard WordPress function, get the dropdown already formatted and solve both problems at once. Like so: define( ‘WP_USE_THEMES’, false ); require( ‘./wp-load.php’ ); wp_dropdown_categories( array( ‘child_of’ => 0, ‘class’ => ‘postform’, ‘depth’ => 0, ‘echo’ => 1, ‘exclude’ => ”, ‘hide_empty’ => false, ‘hide_if_empty’ => false, ‘hierarchical’ => true, ‘id’ => … Read more

How to number the options in a wp_dropdown_pages() select?

To change <option value=”http://someurl”>item one</option> <option value=”http://someurl”>item two</option> <option value=”http://someurl”>item three</option> to <option value=”http://someurl”>1. item one</option> <option value=”http://someurl”>2. item two</option> <option value=”http://someurl”>3. item three</option> we can utilize the list_pages filter from the Walker_PageDropdown::start_el() method. Here’s an example: // Add filter add_filter( ‘list_pages’, ‘wpse_itemize’, 10, 2 ); // Display dropdown wp_dropdown_pages(); // Remove filter remove_filter( ‘list_pages’, … Read more