Solved

How to identify Cateogory name stored on Wordpress database

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to check if a session is disconnected in php 9 32
PHP Curl to output a url 7 49
What if i make webbased alternative for MS Access 5 71
Log in through ID 5 19
This article discusses how to create an extensible mechanism for linked drop downs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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 viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

828 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