• Resolved Houdini

    (@romariokg)


    Hello, I have a need to display the number of ads that were added by the user of the currently viewed ad. It needs to be displayed in the seller-info.php block!

    I’m adding this code, but it displays the total number of free ads for all users!

    <?php do_action(  'rtcl_after_author_meta', $listing->get_owner_id() ); ?> 
    <?php $count_listings = Functions::my_listings_count_as_status(); ?>
    <?php echo esc_html( $count_listings->total ); ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support Ali Akbar Reyad

    (@alireyad)

    Hi,
    You can not use this functional for public user. This functional will work only for logged in user which used in my-account frontend dashboard. You have to develop custom function to do it.

    Thank you

    Thread Starter Houdini

    (@romariokg)

    Where is this function located? I want to look at it as an example. You can give the way.

    I’ll try to develop it, I need it for a project.

    Thread Starter Houdini

    (@romariokg)

    The question is closed, we managed to write a function. I’ll leave it here

    Add to the template’s functions.php file.

    function my_listings_count_as_status() {
    $author_id = get_the_author_meta( 'ID' );
    if ( ! $author_id ) {
    return 'No data for this user';
    }
    $args = [
    'post_type' => 'rtcl_listing',
    'post_status' => 'publish',
    'posts_per_page' => -1,
    'fields' => 'ids',
    'author' => $author_id,
    ];
    $owner_post_count = 0;
    $rtcl_query = new WP_Query( $args );
    if ( $rtcl_query->have_posts() ) {
    $owner_post_count = $rtcl_query->post_count;
    }
    wp_reset_postdata();
    return $owner_post_count;
    }

    Output anywhere in the template:

    <?php $post_count = my_listings_count_as_status();

    if ( $post_count > 0 ) {
    echo '<p>Ads added by this user: ' . esc_html( $post_count ) . '</p>';
    } else {
    echo '<p>This user has no ads.</p>';
    }
    ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.