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

Save_post acf data not updating category of post type

You can not use is_single() conditional tag here. You can check the type of post in the function this way: add_action( ‘save_post’, ‘set_genre_on_save’, 20, 3 ); function set_genre_on_save( $post_id, $post, $update ) { if ($post->post_type != ‘hvm’) return; // … } You can also attach the function to the action hook save_post_{post_type}, which is triggered … Read more

How can I register multiple custom post fields to json?

The $field variable isn’t available inside your get_callback() function. PHP isn’t like JavaScript in that way, and that function can’t access variables from outside its scope (unless it’s global, but that’s a poor solution). To pass the $field variable through to the callback function, you need to write it like this: ‘get_callback’ => function() use … Read more