• Resolved schnubi

    (@schnubi)


    Hi,

    need help in diplaying the counts from posts.

    I have 4 Taxonomies an i waant to generat a “Animated Number” Section with the counts from the post.

    I want to create a template where i insert a shortcode from Advanced Layout Builder to generate the 4 row animatet number section (that allready works)

    Now i need to get the ccounts from the database but i dont know how to do that.

    I could creat 4 templates an read everyone seperate but thats not the clean way, is there a way to get them all in one template?

    Wehn i use this shortcode i only get the Count from the pod bergsteigen but i want to get the count from every pod separate.
    [pods name="bergsteigen" template="Count Bergsteigen" limit="1"]

    Template (Count Bergsteigen)
    {@touren_kategorie.count}

    • This topic was modified 5 years, 4 months ago by schnubi.
Viewing 2 replies - 1 through 2 (of 2 total)
  • If you look at what Pods is doing behind the scenes, it is mainly dealing with meta data, taxonomies, all stuff that lends itself to direct query. The Pod is just a data object that has additoinal information about the type of posts the Pod is attached to, etc.

    What I have started doing is just direct querying, since shortcodes tend to not allow complex queries. So I use Pods to facilitate adding custom fields and using them in my posts, but querying using WordPress built in functions.

    So say you have a custom post type called ‘my-type’, a taxonomy called ‘my_taxonomy’ with some terms, and you have custom fields associated with the ‘my-type’ post. You can query pretty much anything you want using WordPress’s built in query builder. For instance

    $args = array(
    ‘post_type’ => ‘my-type’
    ‘order’ => ‘ASC’,
    ‘meta_query’ => array(
    ‘relation’ => ‘AND’,
    array(
    ‘key’ => ‘my_custom_field_1’,
    ‘value’ => ‘SomeVal’,
    ‘compare’ => ‘=’,
    ),
    array(
    ‘key’ => ‘my_custom_field_2’,
    ‘value’ => ‘AnotherVal’,
    ‘compare’ => ‘>’,
    ),
    ),
    ‘tax_query’ => array(
    array(
    ‘taxonomy’ => ‘my_taxonomy’,
    ‘field’ => ‘slug’,
    ‘terms’ => array(‘some_term’,’other_term’),
    ),
    ),
    )
    );

    $selection = new WP_Query($args);

    From that result you would have count. Notice how this approach lets you specify AND or OR relations, etc. With that tax_query you could also specify a relation type and just add as many arrays as you need with the separate taxonomies. And you can add all sorts of additional info like ‘status’, etc.

    So above method is equivalent of telling WordPress “Get all posts of my custom post type (or some standard type), that have custom fields meeting my criteria, and that are attached to taxonomies as I specify.”

    Pretty powerful approach. Notice also that you specify compare methods, so not just equal to, but greater than. So if you added a date field to a post via Pods, you can use this querying approach to, say, get your posts whose ‘my_date_field’ is greater than some date.

    This might look more complicated than it is. But once you get the hang of it, you might find yourself just building queries for whatever you need.

    Viel Spass!

    Brian

    Plugin Contributor Jim True

    (@jimtrue)

    Pods shortcodes only pull values directly from the Pod. No way for that shortcode to grab counts of posts within the term. As Brian mentions above, since you’re using Taxonomy, functions like that are supported by anything that works with Taxonomy. Custom Post Type Widgets, WP List Posts or any number of plugins that specifically help you build tax queries will work.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show Count from Taxonomies’ is closed to new replies.