Your solution won’t work, because $ep_category->category_parent
is ID (integer) and not slug (string). So this comparison doesn’t make any sense… 😉
One way to do this would be this function (from Codex):
if ( ! function_exists( 'post_is_in_descendant_category' ) ) {
function post_is_in_descendant_category( $cats, $_post = null ) {
foreach ( (array) $cats as $cat ) {
// get_term_children() accepts integer ID only
$descendants = get_term_children( (int) $cat, 'category' );
if ( $descendants && in_category( $descendants, $_post ) )
return true;
}
return false;
}
}
After adding it to your theme, you can use it this way:
if ( in_category( 'watch-isatv' ) || post_is_in_descendant_category( 11 ) ) ... // where 11 is 'watch-isatv' category ID
Related Posts:
- Show content if parent page has children
- Current post’s author name in the author meta tag
- Conditional statement for parent, child and grandchild pages
- Trying to use Ternary operators with WP Conditionals
- When is is_admin() available?
- Check if current page is wp-admin
- Second Navigation inside header
- Using is_page() in functions.php not working at all
- Output 2 items within the Loop
- conditional statement for custom taxonomy
- How to enqueue CSS and JS only on specific template?
- how could I load a different template part by page
- WordPress, AJAX and pre_get_posts using conditional tags
- If tag equals then show else show
- Conditional statement for dates
- How can I display a div ONLY if it is not a certain term page
- Don’t show certain div on front page?
- If ‘editor’ is empty, then
- Add class to DIV depending on page loaded
- How to: Conditionally Enqueue JS and Stylesheets, for Custom Post Type (Single and Archive Templates)
- Undefined index for default custom theme option
- Remove conditional tag from header
- Display an image based on field value
- Multidimensional Array
- Conditional for Post Format
- conditional: if is page, and all subpages
- Woocommerce getting top level category parent and make all sub categories have the same template and menu
- page 1 is not paged
- How to add Text before my Custom Term and hide it when empty
- How can i create a function tag in my plugin
- Add code to the header of posts by particular author
- Display specific page if user signed in
- How to get Post sidebar & footer including html like get_the_content() which only gets content section?
- Widget Logic – display on page and all child
- Need to adjust condition to say if I’m pulling categories from a post, to pull only the first one
- if user is admin display admin link and logout link else display logout only
- Add code only for blog posts
- How to define Og Meta Tags in header using conditions [duplicate]
- If Month=Particular month display content [closed]
- How to echo a different field if another field is empty?
- Adding else if conditional statement to purchased theme
- Conditional in foreach loop is outputting content twice
- Advanced custom fields Repeater conditional statement not working [closed]
- Load slideshow.css file only if Slideshow is checked / on
- Issues trying to add a href statment with PHP into a PHP Echo Statement [closed]
- if is specific custom post in cpt
- advanced custom fields: repeater field within conditional statement [closed]
- WordPress Block Editor Gutenberg running code inside ! is_admin()
- How to fix the admin menu margin-top bug in WordPress 5.5?
- Cleaning up WordPress to improve performance?
- How build a custom login/register form with error handling?
- Network installation giving errors when viewing or adding a user
- The best way to customize “nav-menu-template.php” to add if the ‘link_before’ is “checkbox”
- List all categories but exclude current post category on single post page
- Woocommerce, recognize the loop of related products
- Using FirePHP with WordPress
- WordPress different language footer text
- How do I target the child theme with get_bloginfo();?
- If Meta Checkbox is checked, do something?
- Can I use HTTP POSTs? Is there a better alternative?
- Will simple function names in a class structure conflict with other plugins?
- Getting a specific post values to another div or modal
- How can i upload images in an admin page?
- WP grandchild categories in nested ul li
- Modify HTML structure of fields in woocommerce checkout form
- Retrieve $_POST data submitted from external URL in WordPress(NOT API)
- Update results, Before deleting the related category [closed]
- How to Return in WordPress Function php file?
- Limit Taxonomy Output in Conditional Statement
- wp_redirect only works on main site and not on other sites
- How to filter custom taxonomy term name, slug, and description?
- Rewrite with pagination /foo/page/2/ to posts of a given category, page 2
- Is this a correct usage of ob_start() in my WordPress project?
- How do I get my Javascript scripts working?
- Searching Posts Programmatically in a WordPress Plugin
- Unique PHP on each Page
- Changing wordpress default language
- Contact form – problem with displaying message about sent mail
- How to Redirect Buddypress Directories To Login Page For Non Logged in Users
- Adding image upload in tag section – WordPress plugin development
- How do I set a hidden field to a value?
- Display logged in user name and lastname on page
- WordPress sorting posts by date and title using a dropdown
- How to output the taxonomies that are assigned to each custom post?
- Conditional formatting on data fetched from MYSQL
- opens like sitename.com/URL
- Enqueue script only on child pages of custom post types
- How do I remove an action hook inside a class that is called by another class?
- Merging Multiple WordPress Websites
- Replace an array (with identical values) with another array in the_content
- PHP Error Backtrace / create_function deprecated
- What is wrong in this code?
- wp_nav_menu prints children with parent name
- directorypress theme error mysql_error() [closed]
- wp add inline style in loop
- Do_shortcode on PHP file outside theme ALMOST works
- Does wp_query and query_posts affect website performance? [duplicate]
- Facebook share button only share the_permalink(), without thumbnail, tilte, excerpt, etc
- ACF repeater image in video poster with jquery
- using custom pages for myaccount in woocommerce