Solved

How to identify Cateogory name stored on Wordpress database

Posted on 2016-09-28
2
71 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

Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

Question has a verified solution.

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

Suggested Solutions

This article discusses how to create an extensible mechanism for linked drop downs.
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 prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

734 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