Solved

How to identify Cateogory name stored on Wordpress database

Posted on 2016-09-28
2
52 Views
Last Modified: 2016-09-29
Hi Experts,

We are using a custom fields plugin to display additional data for particular category  . Rite now we have category called
Promotional
and we cant able to retrieve the data for Promotional Category . Here is my code in Single.php from wordpress to target Promotional Category.

$category = get_the_category( $post );
$category_name=$category[0]->cat_name;

if($category_name=='Promotional')
{
            
            
?>
<div class="about-us">
    <div class="container">
        <div class="col-md-12 about-inner">
        <?php the_post(); ?>
            <h1>Promotional - Testubg</h1>
            <div class="color"></div>
        </div>
    </div>
</div>
</div>

<div class="personal">
    <div class="container">
        <div class="col-md-12 per-inn">
            <div class="col-md-4 maid-img">
               
            </div>
             <div class="col-md-8 maid-info">
                <h2>
                    <?php echo get_field('_promotion_period_from'); ?>
                </h2>
                 <h2>
                    <?php echo get_field('_promotion_periodt_to '); ?>
                </h2>
                
            </div>
        </div>
    </div>
 </div>

Open in new window


But i cant able to retrieve those values . Is that any thing am missing

Thanks in Advance Experts
0
Comment
Question by:karthik80c
2 Comments
 
LVL 29

Accepted Solution

by:
Randy Downs earned 500 total points
Comment Utility
Maybe this will help.

If your post has multiple categories it may not be category[0]. You would have to loop through the array and compare each element.

display a list of categories associated with a post

$cats = array();
foreach (get_the_category($post_id) as $c) {
$cat = get_category($c);
array_push($cats, $cat->name);
}

if (sizeOf($cats) > 0) {
$post_categories = implode(', ', $cats);
} else {
$post_categories = 'Not Assigned';
}

echo $post_categories;

Open in new window

1
 

Author Comment

by:karthik80c
Comment Utility
Thanks Randy Downs
1

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Wordpress syntax error 1 27
selecting a category and selecting subcategories 7 30
css question 1 31
.htaccess file settings 4 31
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
This video teaches users how to migrate an existing Wordpress website to a new domain.
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now