Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to identify Cateogory name stored on Wordpress database

Posted on 2016-09-28
2
Medium Priority
?
76 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 30

Accepted Solution

by:
Randy Downs earned 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to implement server side field validation and display customized error messages to the client.
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
Suggested Courses

916 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