Looping to organize and display custom posts by category using PHP and WordPress

Add this after $args $categories = get_terms(‘category’, $args); //get all categories $count = count($categories ); //count categories if ( $count > 0 ){ //Check if you got some categories foreach ( $categories as $category ) { $args[‘cat’] = $category->term_id; //get the id of each category and add it as a parameter $loop_our_work = new WP_Query( … Read more

get_posts changes main query

get_posts() isn’t modifying the main query. The problem is that you’re overwriting the global $post variable in your foreach loop. I guess if you’re in a template then you’re in the same scope as the global variable and don’t need to specify global $post; for this to happen (as you would if you were inside … Read more

Don’t print customizer styles when no setting has been used

There’s not really any trick, you need to check all the values. You can save a little space though, by omitting the != ”, which is redundant: if ( get_theme_mod( ‘myplugin_h2_color’ ) || get_theme_mod( ‘myplugin_h3_color’ ) || get_theme_mod( ‘myplugin_p_color’ ) || get_theme_mod( ‘myplugin_p_size’ ) ) { However, it’s possible to save Customiser settings into a … Read more

How to output and alert message when updating a post

I have developed functionality which is check duplicate value for specific post meta value exist or not on update post. when user update data and if find any record then give a error message in admin dashboard(see attached screenshot). you can use below code according your requirement. class Check_duplicate_entry { public function __construct(){ add_action( ‘save_post’, … Read more