• Resolved pawciak

    (@pawciak)


    Hey!

    I’ve got an issue. The plugin works great with regular pages and posts but what about custom post type? does it support it?

    I create CPT using below code:

    <?php
    
    // Register Custom Post type
    
    $portfolio = new CPT('portfolio', array(
        'supports' => array('title','editor','thumbnail'),
         'has_archive'         => true,
         'publicly_queryable'  => true,
         'capability_type'     => 'post'
    ));
    
    // Register Taxonomy
    
    $portfolio->register_taxonomy(array(
        'taxonomy_name' => 'genre',
        'singular' => 'Genre',
        'plural' => 'Genres',
        'query_var'         => true,
        'rewrite'           => array( 'slug' => 'genre' ),
    ));
    
    $portfolio->register_taxonomy(array(
        'taxonomy_name' => 'client',
        'singular' => 'Client',
        'plural' => 'Clients',
         'query_var'         => true,
        'rewrite'           => array( 'slug' => 'clients' ),
    ));
    
    // define the columns to appear on the admin edit screen
    
    $portfolio->columns(array(
        'cb' => '<input type="checkbox" />',
        'icon' => __('Icon'),
        'title' => __('Title'),
        'genre' => __('Genres'),
        'client' => __('Client'),
        'date' => __('Date')
    ));
    
    // Set post type Dashicon
    
    $portfolio->menu_icon("dashicons-images-alt2");
    
    // Get portfolio items
    
    function get_portfolio_items($count){
    	global $post;
    	 $args = array(
            'posts_per_page' => $count,  // Limit to 5 posts
            'post_type' => 'portfolio',  // Query for the default Post type
        );
    
    	$loop = new WP_Query( $args );
    	echo "<ul class='portfolio-list'>";
    	while ( $loop->have_posts() ) : $loop->the_post(); ?>
    
    	<li class="portfolio-item">
    		<figure class="portfolio-thumb">
    			   <?php echo get_the_post_thumbnail( $post->ID, 'full' );  ?>
    		</figure>
      	  	<h2>  <?php the_title(); ?> </h2>
      	  	<span> <?php echo get_the_term_list( $post->ID, 'genre', 'Genre: ', ', ', '' ) ?> </span>
      	  	<span> <?php echo get_the_term_list( $post->ID, 'client','Client: ', ', ', '' ) ?></span>
    	</li>
    
        <?php endwhile;
        echo "</ul>";
        wp_reset_postdata();
    }
    
    // Portfolio Shortcode
    
    function portfolio_shortcode( $atts ) {
    	$count = 3 ;
    	if( function_exists( 'get_portfolio_items' ) ) {
    			// Attributes
    			extract( shortcode_atts(
    				array(
    					'count' => $count,
    				), $atts )
    			);
    
    		    if( $count != NULL ) {
    		    return get_portfolio_items($count);
    			}
    		}
    	}
    add_shortcode( 'portfolio', 'portfolio_shortcode' );

    Unfortunatelly, even if i properly add the shortcode with gallery, it shows nothing. What i am doing wrong?

    https://www.ads-software.com/plugins/final-tiles-grid-gallery-lite/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Diego

    (@greentreelabs)

    Hi, I guess you’re in the wrong place ?? I don’t recognize your code, also Final Tiles Gallery Lite doesn’t handle posts (only the PRO version).

    Thread Starter pawciak

    (@pawciak)

    Hi! thanks for the quick info. Provided code is mine – thanks to that functions i have additional custom post type. But i asked it here in purpose, i thought that maybe you met such issues with other users.

    what do you mean that gallery doesn’t handle posts? to be clear – i dont want to make a tiled gallery of posts. I want to make a tiled gallery (of images) INSIDE a post.

    and in regular posts plugin works, in custom post – it doesnt.

    Diego

    (@greentreelabs)

    Oh, ok sorry!

    Well, it should be with any kind of post type. Actually I don’t understand where, in your code, it should print the code of my plugin (but maybe it’s because it’s late now ?? ).

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom post type – not working’ is closed to new replies.