Your code will run when the plugin is first initiated, which will be before the post data has been set up. Move all of your code from $cat = get_the_category($id);
up to (but not including) add_filter...
inside the function.
Related Posts:
- Is There a Difference Between Taxonomies and Categories?
- WooCommerce: List All Categories
- Get rid of WordPress category, tag and author archives?
- Filtering categories in the permalink structure
- get_categories hierarchical order like wp_list_categories – with name, slug & link to edit cat
- wp_nav_menu not appearing for a couple pages
- Why aren’t sub-categories nested after creating post in the WP Admin?
- Preventing index.php?category_name=something from redirecting
- How to get category id of current post?
- Programmatically create product category and add thumbnail in woocommerce
- Trash bin for categories
- Categories’ hierarchy in URL
- Display one category in one page
- How to get next previous category in same taxonomy?
- Show Subcategory Description
- is_archive() content being shown instead of is_category()
- Check is category parent or not from its ID
- Which php file lists all the post of a category
- How to query posts from specific authors and categories using WP_query?
- Apply custom category template to subcategories
- Retrieve all posts within tag OR category?
- Include template before a loop
- How to customize tag and category post listings to show introductory content?
- List Terms in Category
- Can you have a single set of “canonical” categories shared by all blogs?
- List Posts by Category for a Non-Zero, Non-NULL Custom Field Value?
- Rename Default Category (Uncategorized) Via a Function
- Highlight wp_nav_menu when category is selected
- How to make 2 tag feeds show up on 1 page?
- Best way of getting WooCommerce category path
- Display the last post by each category?
- Get link which associated with a specific category and tag
- How to disable default category linkbuilding?
- Order categories by name or view count
- How to assign posts without any category to the default category
- Show only first category name in RSS?
- Show parent category in URL of subcategory archive page
- Filter $cpt categories to omit certain category
- Yearly Archive for Categories with dropdown
- get_categories listing foreach with children
- Removing subcategories from permalinks [duplicate]
- How to query categories with Advanced Custom Fields?
- Create category post shortcode
- Undefined property: stdClass::$id when retriving term ID
- Wacky taxonomy in wordpress
- Link to the next/prev posts in index loop in same category?
- Output the text before category
- Change div background acording to the selected category
- get_the_categories() but exclude children of “Uncategorized”
- How to exclude a particular category from the category list
- Why title_li =” not working
- Wrong category nice name is displayed on archive page
- Custom Permalink with child categories creating 404
- Cannot filter categories by parent category
- Redirect year month day postname permalink structure to category postname structure
- Show all sub categories?
- Category nicename inside loop in wordpress
- Exclude all subcategories in the_category (post)
- Displaying another main nav menu for specific category
- Exclude categories from list (wp_list_categories)
- How to display the 5 latest post titles but allow only 1 in there of a specific category
- WordPress: Using the category slug get the category ID using mysql query
- Create a Category with a front-end post
- How to add categories using mysql
- Posts made to category don’t show up (do show up on frontpage)
- Exclude category to “the_breadcrumb” functions
- wp_dropdown_categories() works correctly but the list is not filtered in admin for custom post type. What is the problem?
- Migrate the posts of a category to another blog as a custom taxonomy
- Woocommerce only display child category when parent is checked (on add new product page)
- Add $args to wp_list_categories
- How to hide a category or tag everywhere EXCEPT for use with get_posts
- Show parent category wp_list_categories wordpress
- Taxonomy custom check box meta field not getting saved
- Subcategories randomly not working after page/post/category edit in wordpress. Fix: saving permalinks twice
- In if…else condition, the else statement shows even if if statement is correct
- Restrict retrieved terms by category?
- Get category from slug list
- Re-coding category-template.php to go to custom URL
- Category removal – Portfolio Category:
- How to Change Sort Order of default WordPress Catgory Widgets?
- Show One Level Category id
- Catch 404 after changing permalink structure from /%postname%/ to /%category%/%postname%/
- Custom filters inside a specific category?
- $args Orderby The number
- Most efficient way to have 1 template for parent, 1 template for child categories?
- Function to list posts from current post’s category fails in WP 3.8
- Multiple parent categories
- Custom fields setup when category selected filter subcategories
- How to use Greek characters/letters in a query?
- Make three menus with three category levels
- Getting categories to change appropriately when using $cat = ‘ ‘;
- how to call the category of the post
- Category related -> excerpt, title and thumb in sidebar on article page
- How to have a category not show up in query post with page panigation?
- single category widget with conditional terms
- Remove the current item from a menu
- why is the delete option missing from just one category?
- Get all categories
- Show category post order ASC
- How to display all category images for single post in a page?