Is it possible to use array_walk() to append terms to an array of posts?

I guess you have a problem with variable scopes in here. array_walk($terms, function(&$term, $term_index) { // die(print_r($term)); if (isset($term->slug)) { array_push($post->terms, $term->slug); } }); In this part of your code, you use anonymous function and inside of it you use $post variable. But it is a different variable than the one from few lines back … Read more

Post URL based on Custom Post Types variables

Instead of creating a new tag, I would suggest just writing code to create the slug on a per-post basis using ACF’s save_post function. //Update Cars slug field: function wpse_post_slug_updater( $post_id ) { if( get_post_type() == ‘cars’) { $my_post = array(); $my_post[‘ID’] = $post_id; $my_post[‘post_title’] = esc_html(get_the_title($post_id)); $my_new_slug = get_field(‘brand’) . ‘ ‘ . get_field(‘license_plate’); … Read more

Programmatically add custom field to post_name in a custom post type

You can filter the slug creation on wp_unique_post_slug hook. //Register the filter add_filter(‘wp_unique_post_slug’,’prefix_the_slug’,10,6); function prefix_the_slug($slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug){ //Get value from the custom field $prefix = get_post_meta($post_ID,’cw_event_start_date’,true); //Only prefix certain post type and if prefix field existed if($post_type===’post’ && $prefix && !empty($prefix)){ //Prefix only if it is not already prefixed preg_match (‘/^\d\d\d\d\d\d/’, $slug, … Read more

Get id from metabox dropdown

the_meta is a very bare-bones method. The return value you’re seeing is raw, unserialized data. WordPress uses PHP serialization to store complex values like Arrays and Objects as a string value. Have a look at get_post_meta: $guest_id = get_post_meta( get_the_ID(), ‘episode_guestid’, true ); $guest_post = get_post( $guest_id[0] ); echo ‘<pre>’; print_r( $guest_post ); You should … Read more

Display both parent and child custom taxonomy / content

Here is the code…It may help you to display layout as you wanted. Also Here I have used post type as product and taxonomy as product_cat so you must need to change that as your code. The layout looks like this http://prntscr.com/mjxvzm <?php $post_type=”product”; $taxonomy = ‘product_cat’; $terms = get_terms( array( ‘taxonomy’ => $taxonomy, ‘hide_empty’ … Read more