troubleshooting Question

Display number of posts count in a foreach loop for current vendor.

Avatar of Andrew Spackman
Andrew Spackman asked on
4 Comments1 Solution27 ViewsLast Modified:

I am trying to find a way I can output a counter that displays the number of unread announcements my vendors have.

The announcements are a custom post type called 'dokan_announcement'

I have the following code that displays the widget of announcements in the dashboard area.

 *  Dokan Dashboard Template
 *  Dokan Dahsboard Announcement widget template
 *  @since 2.4
 *  @package dokan
 <div class="dashboard-widget dokan-announcement-widget">
    <div class="widget-title">
        <?php _e( 'Latest Notifications', 'dokan' ); ?>

    <?php if ( $notices ): ?>
        <ul class="list-unstyled">
            <?php foreach (array_slice($notices, 0, 2)  as $notice ): ?>
                    $notice_url =  trailingslashit( dokan_get_navigation_url( 'single-announcement' ).''.$notice->ID );
                    <div class="dokan-dashboard-announce-date <?php echo ( $notice->status == 'unread' ) ? 'dokan-dashboard-announce-unread' : 'dokan-dashboard-announce-read'; ?>">
                        <span class="announce-day"><?php echo date_i18n( 'd', strtotime( $notice->post_date ) ); ?></span>
                        <span class="announce-month"><?php echo date_i18n( 'M', strtotime( $notice->post_date ) ); ?></span>
                        <span class="announce-year"><?php echo date_i18n( 'Y', strtotime( $notice->post_date ) ); ?></span>
					<div class="dokan-dashboard-announce-content">
                        <a href="<?php echo $notice_url; ?>"><h3><?php echo $notice->post_title; ?></h3></a>
						<p><?php echo wp_trim_words( $notice->post_content, 8, '...' ); ?></p>
                    <div class="dokan-clearfix"></div>
            <?php endforeach ?>
	 	<a class="btn-vendor-primary mb-0" href="<?php echo $announcement_url; ?>"><?php _e( 'See All Notifications', 'dokan' ); ?></a>
    <?php else: ?>
        <div class="dokan-no-announcement">
            <div class="annoument-no-wrapper">
                <img class="dokan-announcement-icon" src="<?PHP echo get_template_directory_uri();?>/inc/images/icons/bell-thin.svg" alt="Bell"/>
                <p><?php _e( 'No notifications', 'dokan' ) ?></p>
    <?php endif ?>
</div> <!-- .products -->

Open in new window

So what I am trying to achieve is a check to see if the current_user or vendor has any unread posts ($notice->status == 'unread') loop through and display the number of these else display nothing.

Many Thanks,

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros