How to display custom post type only on a certain page?

Very difficult to answer given the information provided but you probably want … ‘has_archive’ => false, ‘rewrite’ => array(‘slug’=>”https://wordpress.stackexchange.com/”,’with_front’=>false), … as part of your arguments when you register the post type and then you can add the post type to the main query for that home/front page… function add_cpt_to_home($qry) { if (is_front_page() || is_home()) { … Read more

Custom post type hierarchical loop in Homepage

From the look of your code, all you are doing is creating a nested list. If so, the easiest thing would be wp_list_pages. $args = array( ‘post_type’ => ‘cliente’, ‘post_status’ => ‘publish’, ‘author’ => $idutente, // must be comma separated list of IDs ); wp_list_pages($args); wp_list_pages only seems to work with ‘hierarchical’ => true,, but … Read more

Add Class After 4th Post

Just check $wp_query->current_post instead of using that mod operator. if ($wp_query->current_post === 4) { ?> <div class=”vender_hr”></div> <?php } But don’t use query_posts. Create a new WP_Query object. What you are doing is kind-of weird. You are checking to see if there are posts, then clobbering the main query which invalidates the have_posts check you … Read more

add_query_arg() for custom post type on all visible links

Filter post_type_link instead. This is reserved for custom post types, and you get the post object, so you don’t need a global variable for this. is_admin() or add_filter( ‘post_type_link’, ‘career_position_url’, 10, 2 ); function career_position_url( $url, $post ) { global $career_mb; if ( ‘career’ !== $post->post_type ) return $url; $career = $career_mb->the_meta(); return add_query_arg( ‘position’, … Read more

Control Loop Within Loop

I think you want something more like this: $args = array( ‘post_type’ => ‘testimony’, ); $testimony = new WP_Query($args); if ( have_posts() ) { while ( have_posts() ) { the_post(); if ( 0 !== $wp_query->current_post && 0 === $wp_query->current_post%3 && $testimony->have_posts() ) { $testimony->the_post(); echo ‘inner-loop’; the_title(); echo ‘inner-loop’; echo ‘<br>’; } wp_reset_postdata(); the_title(); echo … Read more

Custom Posts and Posts – next_post_link and previous_post_link not working together

You will need a filter on get_{$adjacent}_post_where to add your CPT. function alter_adj_where_wpse_106694($where) { $where = str_replace(“p.post_type=”post””,”p.post_type IN (‘post’,’yourcpt’)”,$where); return $where; } add_filter(‘get_next_post_where’, ‘alter_adj_where_wpse_106694’ ); add_filter(‘get_previous_post_where’, ‘alter_adj_where_wpse_106694’ ); There is no flexibility to that callback. It is a simple string replace. If this is your site you should be OK, but if this is a … Read more