how let users select categories for posts in frontend?

here is how to do it: <form action=”#” method=”post”> <input type=”checkbox” name=”checklist[]” value=”1″><label>Blue</label> <input type=”checkbox” name=”checklist[]” value=”2″><label>Red</label> … <input type=”submit” name=”submit” value=”submit”/> </form> <?php if(isset($_POST[‘submit’])){ if(!empty($_POST[‘checklist’])){ $selectArr = array(); foreach($_POST[‘checklist’] as $selected){ $selectedInt = (int)$selected; $selectArr[] = $selectedInt; wp_set_object_terms( $thePostId, $selectArr, ‘color’); } } } ?> where the values in input tags are taxonomies IDs … Read more

Creating a link to the first post in a category

Given a category ID, in this example as the variable $cat_id, you would do this by querying 1 post in that category, ordered by date in ascending order (oldest first). Then use that result to get the permalink to that post. $posts = get_posts( ‘numberposts’ => 1, ‘order’ => ‘ASC’, ‘cat’ => $cat_id, ); if … Read more

Let user select the number of posts shown per page jquery error

A simple fix would be to change the query name; i.e. from page to pageVal. <script> jQuery(document).ready(function( $ ) { $(‘.page-select’).change(function(){ var checkIndex = ( window.location.href || ” ).indexOf(‘?’); if( checkIndex > -1 ){ var Link = window.location.href.substr(0, checkIndex-1); $(location).attr(‘href’, Link+’?pageVal=”+$(“.page-select’).val()); } else { $(location).attr(‘href’, window.location.href+’?pageVal=”+$(“.page-select’).val()); } }); }); </script> But I’d use this..: <script> … Read more

Page with Category Returning 1

few things here: 1) Your WP_Query args doesn’t look good, the proper way of querying posts by taxonomy should be: $splash_page_args = array( ‘post_type’ => ‘page’, ‘posts_per_page’ => ‘3’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => ‘splash-homepage’, ), ), ); 2) Is there any particular reason why you’re using foreach … Read more

Custom Post Types and Broken Permalinks

You need to flush rewrite rules on plugin activation for your custom post type to begin working. register_deactivation_hook( __FILE__, ‘flush_rewrite_rules’ ); register_activation_hook( __FILE__, ‘myplugin_flush_rewrites’ ); function myplugin_flush_rewrites() { // call your CPT registration function here // (it should also be hooked into ‘init’) dwwp_register_post_type(); flush_rewrite_rules(); } You may have noticed it randomly working without having … Read more