Aleš Sýkora wrote

Taxonomy Post Count for Custom Post Type

16. 5. 2019 in

Add this snippet to your functions.php or create your own plugin:

function my_taxonomy_posts_count_func( $atts ) {
    extract(shortcode_atts(array(
    'post_type' => 'post',
    ), $atts));
    global $WP_Views;
    $term = $WP_Views->get_current_taxonomy_term();
    
    $args = array(
    'post_type'=> $post_type,
    'tax_query' => array(
    array(
    'taxonomy' =>$term->taxonomy,
    'field' => 'id',
    'terms' => $term->term_id,
    )
    ),
    'order' => 'ASC',
    'posts_per_page' => -1,
    'suppress_filters' =>0,
    );
    $posts = get_posts( $args );
    $res=0;
    if($posts)
    {
    $res = count($posts);
    }
    return $res;
    
    }
    
add_shortcode( 'my-taxonomy-posts-count', 'my_taxonomy_posts_count_func' );

Add this shortcode to your view:

[my-taxonomy-posts-count post_type="jobs"]

And change the “jobs” to your CPT slug.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

More from category
Aleš Sýkora wrote
Disable Woocommerce image zoom on hover in oxygen
19. 11. 2020 in ,
Add this to custom snippets. Or put in custom funcionalities plugin. Dont worry, lightbox will be working. Then the magnyfing glass icon dissapears, the over effect is gone, but the lightbox works perfect :-).
Read More
Aleš Sýkora wrote
Show Oxygen Element by current language with WPML
26. 4. 2021 in ,
When you use WPML with Oxygen Builder and use 1 template for all languages, then you propably want to display/hide elements conditionally. And of course you can. Use the WPML’s filter wpml_current_language to get current language code. Then use the if function to return value you want. I am returning the language code and then […]
Read More
Aleš Sýkora wrote
Change GDPR field response data in Fluent Forms
15. 4. 2021 in
If you want to change the “Accepted” to something else, use the first snippet and change the $response variable. If you want to change the Terms and Condition and GDPR field response, use this code:
Read More
magnifiercross linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram