0

I have to count how many times my custom post type date enclosed in my metakey:metakey_AMC_data, it is the same as the current date and belongs to a specific taxonomy

I can't get this to work:

try 1:with this, i have 4 result but not the truth because i have only one

<?php
$mostra_data_corrente = date('d-m-Y');
$args = array(
    'post_type' => 'eventi-suite',
    'meta_query' => array(
        array(
            'key'       => 'metakey_AMC_data',
            'type'              => 'DATE',
            'meta_value'        => $mostra_data_corrente,
        )
    ),
    'tax_query' => array(
        array(
            'taxonomy'  => 'categoria',
            'field'     => 'slug',
            'terms'     => $queried_object,
        )
    ),
    'post_status'   => 'publish',

);
$query = new WP_Query( $args );
$conta_risultati =  count($args);
echo $conta_risultati;
?>

try 2: I can't determine the part of the taxonomy, and doing it for id is madness

    global $post;
    $show_id = $post->ID;
    $mostra_data_corrente = date('d-m-Y');
    global $wpdb;
    $query = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}postmeta, {$wpdb->prefix}term_relationships
                                        WHERE (meta_key = 'metakey_AMC_data' 
                                        AND meta_value = '$mostra_data_corrente'
                                        AND object_id = $show_id) ");
    $conta_risultati =  count($query);

I would simply like to count how many times the date of my meta key in (d-m-y) format is present inside the db, only posts from a given taxonomy

0

WP_Query has a property that returns the no of posts that match your query.

You can print it as follow in your first try:

$query = new WP_Query( $args );

echo $query->post_count;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.