Solved

How to identify Cateogory name stored on Wordpress database

Posted on 2016-09-28
2
72 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 30

Accepted Solution

by:
Randy Downs earned 500 total points
ID: 41822544
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
ID: 41822879
Thanks Randy Downs
1

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

632 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