Custom Post type & Taxonomy 404

Please replace the “portfolio_create_taxonomy” funcation to below code function portfolio_create_taxonomy() { register_taxonomy( ‘portfolio-category’, array( ‘portfolio’ ), array( ‘hierarchical’ => true, ‘show_ui’ => true, ‘show_admin_column’ => true, ‘query_var’ => true, ‘label’ => __( ‘Category’ ), ‘rewrite’ => array( ‘slug’ => ‘portfolio-category’ ), ‘hierarchical’ => true, ) ); } add_action( ‘init’, ‘portfolio_create_taxonomy’ );

Custon Content within WordPress Loop

You can use current_post field of WP_Query to check inside the loop, or you can break the loop in two loops. Here are code samples: <?php $services_loop = new WP_Query( array( ‘post_type’ => ‘service’, ‘posts_per_page’ => -1 ) ); while ( $services_loop->have_posts() ) : $services_loop->the_post(); ?> <section class=”single-service”> <div class=”container”> <div class=”row”> <div class=”col-md-6″> <?php … Read more

Getting Un Wanted Gallery Shortcode In The Page on Loop

All filters applied to the ‘the_content’ hook (including shortcode rendering) are not applied when you call get_the_content(). This is why you get raw shortcode from your content. You could use the_content() instead, or use apply_filters directly in your template. In other words, replace this line: echo ‘<p class=”p-paragraph” style=”text-align:left”>’. get_the_content().'</p>’; with either (preferred method): echo … Read more

Using wp_localize_script to get data from cpt and pass it to maplace-js locations

You don’t need to use json_encode() when using wp_localize_script(). The last argument of wp_localize_script() should be a PHP array. This will be converted to JSON for you. So to resolve the issue, remove this line: $location_json = json_encode($location_array); And change wp_localize_script() to use $location_array: wp_localize_script(‘sage/main.js’, ‘locationJSON’, $location_array); Because $location_array had been double-encoded the locationJSON variable … Read more

Custom URL redirect in WP

The problem is with this expression: filter_var($url, FILTER_VALIDATE_URL) !== true which should or could be written as just: filter_var($url, FILTER_VALIDATE_URL) Because the PHP manual for filter_var() says: Returns the filtered data, or FALSE if the filter fails. which means, with a valid URL, filter_var() does not return a boolean; hence filter_var($url, FILTER_VALIDATE_URL) !== true never … Read more

How to automatic update date and time when save custom post type

Using your example link, I just added an IF to check for post_type. function reset_post_date_wpse_121565($data,$postarr) { // var_dump($data,$postarr); die;// debug if($data[‘post_type’] == ‘new_cpt’){ $data[‘post_date’] = $data[‘post_modified’]; $data[‘post_date_gmt’] = $data[‘post_modified_gmt’]; return $data; } } add_filter(‘wp_insert_post_data’,’reset_post_date_wpse_121565′,99,2);

multiple custom post type on category page

Add to $post_type array, don’t replace it… function dog_query_post_type($query) { if( is_category() && $query->is_main_query() && empty( $query->query_vars[‘suppress_filters’] ) ) { $post_type = get_query_var(‘post_type’); if($post_type) $post_type[] = ‘dog’; else $post_type = array( ‘post’, ‘dog’, ‘nav_menu_item’); $query->set(‘post_type’,$post_type); return $query; } } add_filter(‘pre_get_posts’, ‘dog_query_post_type’);

the_content(); of custom post type treated as an array or object

single-book.php should not have a custom query in it. WordPress has already queried the correct post, so new WP_Query( $args ) is completely unnecessary. Your problem is that you’re missing the loop. At the bare minimum single-book.php should have: <?php while ( have_posts() ) : the_post(); ?> <h1><?php the_title(); ?></h1> <?php the_content(); ?> <?php endwhile; … Read more

Multiple Custom Post Type queries, how to DRY it up

The below example is your code in a loop. The post_types array includes all the post types that you’re querying. Then, the next bit (foreach, more info here) runs the code wrapped in curly braces ({ to }) for each item in that post_types-array. post_types = array(‘recipes’, ‘value_chain’, ‘press’, ‘multimedia’); foreach($post_types as $post_type){ $query = … Read more