• Skip to main content
  • Skip to primary sidebar

WordPress, Genesis Framework and Storefront customization tutorials

  • Archive
    • Free
    • Premium
  • Design
  • Blog
  • About
  • Contact
  • Newsletter
  • Membership
    • Login
Home » CPT

CPT

Echo custom post type taxonomy name and slug with function

Filed Under: Free Tagged With: CPT

How to Show Total Number of Posts, Pages, or Custom Post Types

Filed Under: Free Tagged With: CPT, PHP

Display title of current Custom Post Type’s taxonomy

    $terms = get_the_terms( $post->ID, 'YOUR_TAXONOMY' ); 
    foreach($terms as $term) { 
        echo $term->name; 
        echo $term->slug; 
    } 

Filed Under: Free Tagged With: CPT, Taxonomy

Echo something conditionally on the single page of specific Custom Post Type Taxonomy

// ==================================================================
// SINGLE PAGE OF SPECIFIC CPT TAXONOMY
// ==================================================================
function single_page_of_specific_cpt_taxonomy(){
    global $post; 
    if(is_singular('YOUR_CPT')){
       foreach (get_the_terms(get_the_ID(), 'YOUR_TAXONOMY') as $cat) {
           //echo $cat->slug;
           if($cat->slug === 'YOUR_TERM'){
               echo 'YEAHHH!!!!';
           }
        }
    }
}
add_action('genesis_entry_content', 'single_page_of_specific_cpt_taxonomy');

Filed Under: Free Tagged With: CPT

How to Make Custom Post Type Child of Page

'rewrite' => array(
            'slug' =>  get_post_field( 'post_name', get_option('cpt_parent_page') ) . '/PARENT/YOUR_POST_TYPE',
            'with_front' => false
)

Filed Under: Free Tagged With: CPT

Custom Post Type and Taxonomy

Remove slug from custom post type post URLs

If You don’t want to use the Custom Post Type’s slug, just paste this snippet in your functions.php and rewrite the post type:

Filed Under: Free Tagged With: CPT

How to fix Yoast breadcrumb in Custom Post Types

Create a file called breadcrumb-fix.php

<div class="breadcrumb-wrapper">
<?php
    if ( function_exists('yoast_breadcrumb') ){
    
            if(get_post_type() == 'szolgaltatas'){

                include('breadcrumb-services.php');  
            }
            elseif(get_post_type() == 'post'){

                include('breadcrumb-post.php');  
            }
            else { 
                    yoast_breadcrumb( '<p id="breadcrumbs">','</p>' ); 
                } 
        }
?>
</div>

Create another file

<p id="breadcrumbs">
        <span xmlns:v="http://rdf.data-vocabulary.org/#">
            <span typeof="v:Breadcrumb">
                <a href="<?php echo home_url(); ?>/" rel="v:url" property="v:title">
                    wtsklient.hu
                </a>
            </span>
                <i class="fas fa-chevron-right"></i>
            <span typeof="v:Breadcrumb">
                    <?php lang_post_breadcrumbs(); ?>
            </span>
                <i class="fas fa-chevron-right"></i>
            <span typeof="v:Breadcrumb">
                <span class="breadcrumb_last" property="v:title">
                    <?php the_title(); ?>
                </span>
            </span>
        </span>
</p>

Create a function for 3 languages

/****************************************************
//BREADCRUMBS POSTS
****************************************************/
function lang_post_breadcrumbs(){
    if(ICL_LANGUAGE_CODE=='hu'){
        echo '<a href="#">Hírek</a>';
        }
    elseif(ICL_LANGUAGE_CODE=='en'){
        echo '<a href="#">News</a>';    
        }
    elseif(ICL_LANGUAGE_CODE=='de'){
        echo '<a href="#">Nachrichten</a>';    
        }
}

Filed Under: Free Tagged With: CPT

Search only in specific Custom Post Types

//Search only in specific Custom Post Types
function searchfilter($query) {
 
    if ($query->is_search && !is_admin() ) {
        $query->set('post_type',array('post','page'));
    }
 
return $query;
}
 
add_filter('pre_get_posts','searchfilter');

Filed Under: Free Tagged With: CPT

Add Images to CPT Taxonomy

I use for add images to categories this plugin: Categories Images

<div class="grid row kategoria">
    <?php foreach (get_terms('kategoria') as $cat) : ?>
        <div class="col-xs-12 col-sm-6 col-md-3">
            <a class="cat-link" href="<?php echo get_term_link($cat->slug, 'kategoria'); ?>">
               <figure class="effect-ming">
                    <img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />
                    <figcaption>
                        <h2 class="kategoria"><?php echo $cat->name; ?></h2>
                        <p class="hover hide"><?php echo $cat->name; ?></p>
                    </figcaption>	
                </figure>
             </a>
        </div>
    <?php endforeach; ?>
</div>

Filed Under: Free Tagged With: CPT

Custom Post Type Taxonomy Archive Page in Genesis

Create a file with name taxonomy-yourtaxonomy.php

<?php

//Include taxonomy template file
add_action('genesis_entry_header', 'add_custom_category');
function add_custom_category(){
    include('loop/taxonomy-archive.php');
}

//Add wrapper open 
add_action('genesis_before_while', 'add_grid_wrapper_open');
function add_grid_wrapper_open(){
    echo '<div class="grid row">
            
        ';
}

//Add wrapper close 
add_action('genesis_after_endwhile', 'add_grid_wrapper_close');
function add_grid_wrapper_close(){
    echo '
        </div>';
}
genesis();

Create another file in loop folder with name taxonomy-archive.php

<div class="card melo">
    <a href="<?php the_permalink(); ?>">
        <?php the_post_thumbnail( 'full', array('class' => 'card-img-top') ); ?>
    </a>
        <div class="card-body">
            <h4 class="card-title"><?php the_title(); ?></h4>
            <div class="card-text">
               
            </div>
        </div>
</div>

Filed Under: Free Tagged With: CPT, Genesis

How to echo CPT taxonomy name and slug

Echo taxonomy slug

<?php foreach (get_the_terms(get_the_ID(), 'your_taxonomy') as $cat) {
   echo $cat->slug;
}
?>

Echo taxonomy name

<?php foreach (get_the_terms(get_the_ID(), 'your_taxonomy') as $cat_name) {
   echo $cat_name->name;
}
?>

Filed Under: Free Tagged With: CPT

Loop Custom Post Type Sub Category

<?php
wp_reset_postdata();
  
$args = array(
           'post_type'      => 'posttype',
           'posts_per_page' => 20,
           'tax_query' => array(
               array(
                   'taxonomy' => 'taxonomy',
                   'field'    => 'slug',
                   'terms'    => 'subcategory',
               ),
           ),
       );                  

$query = new WP_Query( $args ); ?>
 
<?php if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post(); ?>
 
 
 
<?php endwhile; endif; ?>
 
<?php wp_reset_postdata(); ?>

Filed Under: Free Tagged With: CPT

Loop Zillow CPT

To view the full content, please sign up for the membership.

If You are already a member, please log in below:

 
 
Forgot Password

Filed Under: Premium Tagged With: CPT

Primary Sidebar

MacBook

12 Essential Snippets for Genesis Developers

Subscribe to my Newsletter to view my basic collection of Genesis snippets that I use for my projects!

Sign Up for Free
Gabor Flamich

Hi! I'm Gabor.
I write tutorials on WordPress, Genesis Framework and WooCommerce.

  • Facebook
  • GitHub
  • Instagram
  • LinkedIn
  • Twitter
  • YouTube
WP Rocket - WordPress Caching Plugin
UpdraftPlus Premium

Tags

ACF Ajax Analytics Animation API Bootstrap Breadcrumb Card category CPT CSS Genesis Git Google Maps Grid GSAP Gutenberg htaccess HTML JavaScript jQuery json landing layout Map masonry Menu Parallax PHP SASS skew SQL Storefront SVG tab tag manager tags Taxonomy Tool upsell Wholesale WooCommerce WordPress WPML

Disclosure: Some of the links in this site are affiliate links. I will be paid a commission if you use this link to make a purchase.

  • Privacy Policy / Terms of Service
© 2021 WP Flames - All Right Reserved