Search
 
SCRIPT & CODE EXAMPLE
 

PHP

get taxonomy term id from slug - WordPress

<?php 
    $term = get_term_by('slug', $slug, 'category'); 
    $name = $term->name; 
    $id = $term->term_id;
?>
Comment

How do I get current taxonomy "term id" on wordpress?

$obj = get_queried_object();
echo $obj->term_id;
Comment

taxonomy-{taxonomy-slug}.php

taxonomy-{taxonomy}-{slug}.php
taxonomy-{taxonomy}.php
taxonomy.php
archive.php
index.php
Comment

taxonomy-{taxonomy-slug}.php

add_action( 'init', 'create_post_type' );
function create_post_type() {
    register_post_type( 'products',
        array(
            'labels' => array(
                'name' => __( 'Products' ),
                'singular_name' => __( 'Product' )
            ),
        'capability_type' => 'post',
        'supports' => array('title','editor','comments'),   
        'public' => true,
        'has_archive' => true,
        'rewrite' => array( 'slug' => 'products' ),
        )
    );
}

function news_init() {
    // create a new taxonomy
    register_taxonomy(
        'products',
        'products',
        array(
            'label' => __( 'Product Categories' ),
            'sort' => true,
            'hierarchical' => true,
            'args' => array( 'orderby' => 'term_order' ),
            'rewrite' => array( 'slug' => 'products-category' )
        )
    );      
}
add_action( 'init', 'news_init' );
Comment

PREVIOUS NEXT
Code Example
Php :: php time how long a function takes 
Php :: php get extension from string 
Php :: codeigniter 4 pagination descending 
Php :: convert string to date php 
Php :: get request uri from request laravel 7 
Php :: for install perticular version in vue with laravel 
Php :: php artisan make migration 
Php :: Drupal 9 cache killer kill switch 
Php :: redirect all request to public folder laravel htaccess 
Php :: pdo fetch 
Php :: witherrors laravel 
Php :: carbon time ago laravel 
Php :: laravel grouping routes 
Php :: how to add properties to the request object in laravel 
Php :: get post title by post id wordpress 
Php :: for loop php continue to next item 
Php :: php add days to date 
Php :: add action wp_footer 
Php :: php artisan make:request 
Php :: php sleep milliseconds 
Php :: Changer le logo Admin WordPress 
Php :: force https redirect php 
Php :: whats the meaninig of void functions in php 
Php :: randomize question in laravel 
Php :: integer division in php 
Php :: calcul age php datetime 
Php :: php extract email address from string 
Php :: check if $_files is empty php 
Php :: wordpress display post comment number 
Php :: phpmyadmin max upload 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =