Is there An Input Checkbox Option That Works like `wp_dropdown_categories()` To Use In A WP Search Form?

Yes, there is a built-in WordPress function you can use to render a list of checkboxes (or simply, checklist) which then allows the user to select multiple terms, and the function is wp_terms_checklist(). However, the function only works for users who have the capability/permission to assign terms to a post, so you’d need to create … Read more

Randomly placed sticky custom posts complemented by blog posts

This did it: $products = get_posts(array(‘post_type’ => ‘products’)); $numbers = range(0, 8); shuffle($numbers); $x = 0; foreach($products as $post) : setup_postdata($post); $product = new WP_Query(array(‘p’=>$post->ID,’post_type’=>’products’)); if (!empty($product->posts)) array_splice($posts,$numbers[$x],0,$product->posts); $x++; endforeach; foreach($posts as $post) : setup_postdata($post); …

Adding Custom Metaboxes to Custom Pages

The add_meta_boxes hooks load in edit-form-advanced.php. Your custom plugin page “test” does not use that file. You need to hook into the “plugin admin page hooks” instead. Secondly, the third parameter of add_meta_box is just the CPT slug, not the page slug you have. Here is what you need to change: add_action(“load-my-cpt_page_my-cpt-slug”, “my_add_metaboxes”); function my_add_metaboxes() … Read more

Display posts in random post types

There is no easy query that will do that (see below). You will need to process your results in PHP to get the sort you are looking for. Something like this: $args = array( ‘posts_per_page’ => 5, ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’, ‘post_type’ => array(‘post’, ‘book’), ‘post_status’ => ‘publish’ ); $posts = get_posts( $args … Read more

How can I add single catogory for custom post type?

You can add this line to the code which registers your Custom Post Type: ‘taxonomies’ => array( ‘category’ ), Or you could add Taxonomies rather than categories: add_action( ‘init’, ‘cpt_type_taxonomy’ ); function cpt_type_taxonomy() { register_taxonomy( ‘portfolio-type’, ‘portfolio’, array( ‘labels’ => array( ‘name’ => _x( ‘Types’, ‘taxonomy general name’, ‘theme’ ), ‘add_new_item’ => __( ‘Add New … Read more

Set default option in dropdown of WP_Query?

(Revised answer) If I understand it properly, try these: Define $the_post for each “property”: <?php $the_post = get_post(); ?> <div class=”property-details”> <h2><?php the_title(); ?></h2> … </div> Then change the drop-down code to: <select name=”propname”> <?php $found = wp_list_filter( $the_query->posts, [ ‘ID’ => $the_post->ID ] ); if ( empty( $found ) ) : ?> <option selected><?php … Read more