-
AuthorPosts
-
November 3, 2015 at 11:03 am #650963
Hi, there.
I’ve developed a plugin to manage swimming competitions. With that, I’ve registered two custom post types, one is athletes and the other is competitions. In Recent Posts everything works fine except for this two CPTs..I’m able to view just one of them, the last one in particular. In Cornerstone settings though I can view both of them…
Could you please give me a hint about how I can resolve this issue?Thanks very much
PS I’m using WordPress 4.3.1, X 4.1.1 and Cornerstone 1.0.6
November 3, 2015 at 11:11 am #650977Hello Raffaella,
Thanks for writing in!
Would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:
– Link to your site
– WordPress Admin username / password
– FTP credentialsDon’t forget to select Set as private reply. This ensures your information is only visible to our staff.
Thanks.
November 3, 2015 at 12:31 pm #651086This reply has been marked as private.November 3, 2015 at 6:25 pm #651479Hello Raffaella,
Thank you for the complete credentials above.
Please find this code on your child theme’s functions.php file:function add_event_post_type( $types ) { $types['dkkr_competitions'] = 'dkkr_competitions'; return $types; } add_filter( 'cs_recent_posts_post_types', 'add_event_post_type', 999 );
Then replace with this:
function add_event_post_type( $types ) { $types['dkkr_competitions'] = 'dkkr_competitions'; $types['dkkr_athletes'] = 'dkkr_athletes'; return $types; } add_filter( 'cs_recent_posts_post_types', 'add_event_post_type', 999 );
Hope this helps.
November 4, 2015 at 3:47 am #651906Hello there!
Yes, it works!!! The only thing I had to fix was obviously the category, that has to match with the one of my custom post type.
So, if anyone needs to add his own custom post type with his own taxonomies, the code to add to functions.php in the child theme is the following:
function add_event_post_type( $types ) { $types['your-custom-post-type-1'] = 'your-custom-post-type-1'; $types['your-custom-post-type-2'] = 'your-custom-post-type-2'; ... return $types; } add_filter( 'cs_recent_posts_post_types', 'add_event_post_type', 999 );
Then overriding the recent posts shortcode
function x_shortcode_recent_posts_override( $atts ) { extract( shortcode_atts( array( 'id' => '', 'class' => '', 'style' => '', 'type' => 'post', 'count' => '', 'category' => '', 'offset' => '', 'orientation' => '', 'no_image' => '', 'fade' => '' ), $atts, 'x_recent_posts' ) ); $allowed_post_types = apply_filters( 'cs_recent_posts_post_types', array( 'post' => 'post', 'your-custom-post-type-1' => 'your-custom-post-type-1', 'your-custom-post-type-2' => 'your-custom-post-type-2', ... => ... ) ); $type = ( isset( $allowed_post_types[$type] ) ) ? $allowed_post_types[$type] : 'post'; $id = ( $id != '' ) ? 'id="' . esc_attr( $id ) . '"' : ''; $class = ( $class != '' ) ? 'x-recent-posts cf ' . esc_attr( $class ) : 'x-recent-posts cf'; $style = ( $style != '' ) ? 'style="' . $style . '"' : ''; $count = ( $count != '' ) ? $count : 3; $category = ( $category != '' ) ? $category : '';
Now this line
$category_type = ( $type == ‘post’ ) ? ‘category_name’ : ‘portfolio-category’;
has to be replaced with thisif ($type == 'x-portfolio' ): $category_type = 'portfolio_category'; elseif ($tye == 'your-custom-post-type-1' ): $category_type = 'your-custom-taxonomy-1'; elseif ($type == 'your-custom-post-type-2' ): $category_type = 'your-custom-taxonomy-2'; elseif (...) else: $category_type = 'category_name'; endif;
And then again
$offset = ( $offset != '' ) ? $offset : 0; $orientation = ( $orientation != '' ) ? ' ' . $orientation : ' horizontal'; $no_image = ( $no_image == 'true' ) ? $no_image : ''; $fade = ( $fade == 'true' ) ? $fade : 'false'; $js_params = array( 'fade' => ( $fade == 'true' ) ); $data = cs_generate_data_attributes( 'recent_posts', $js_params ); $output = "<div {$id} class=\"{$class}{$orientation}\" {$style} {$data} data-fade=\"{$fade}\" >"; $q = new WP_Query( array( 'orderby' => 'date', 'post_type' => "{$type}", 'posts_per_page' => "{$count}", 'offset' => "{$offset}", "{$category_type}" => "{$category}", '' ) ); if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post(); if ( $no_image == 'true' ) { $image_output = ''; $image_output_class = 'no-image'; } else { $image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'entry-cropped' ); $bg_image = ( $image[0] != '' ) ? ' style="background-image: url(' . $image[0] . ');"' : ''; $image_output = '<div class="x-recent-posts-img"' . $bg_image . '></div>'; $image_output_class = 'with-image'; } $output .= '<a class="x-recent-post' . $count . ' ' . $image_output_class . '" href="' . get_permalink( get_the_ID() ) . '" title="' . esc_attr( sprintf( __( 'Permalink to: "%s"', csl18n() ), the_title_attribute( 'echo=0' ) ) ) . '">' . '<article id="post-' . get_the_ID() . '" class="' . implode( ' ', get_post_class() ) . '">' . '<div class="entry-wrap">' . $image_output . '<div class="x-recent-posts-content">' . '<h3 class="h-recent-posts">' . get_the_title() . '</h3>' . '<span class="x-recent-posts-date">' . get_the_date() . '</span>' . '</div>' . '</div>' . '</article>' . '</a>'; endwhile; endif; wp_reset_postdata(); $output .= '</div>'; return $output; } add_action('init', 'x_overwrite_shortcode'); function x_overwrite_shortcode() { remove_shortcode( 'x_recent_posts' ); add_shortcode( 'x_recent_posts', 'x_shortcode_recent_posts_override' ); }
Thanks X Staff for your help!!!!
November 4, 2015 at 4:17 am #651950Glad you’ve sorted it out 🙂
And thanks for sharing!
-
AuthorPosts