So after consulting on Facebook Advanced WordPress group, the advice was to create an object with setters and getters instead of using the declaring and getting variables in the global scope as shown in the code below:
class MyPlugin
{
public $current_post_types;
public function __construct()
{
add_filter('init', array($this, 'get_variables'));
}
public function get_variables()
{
$this->current_post_types = get_post_types(array(
'public' => true,
'show_in_rest' => true,
), 'objects');
}
}
$skeleton = new MyPlugin();
function mk_post_types()
{
global $skeleton;
$current_post_types = $skeleton->current_post_types;
//remaining code below
}
This solved the issue, now I can get all custom post types in the mk_post_types function.
Related Posts:
- Saving Taxonomy Terms
- Adding a drag and drop re-ordering from a custom post type default list [closed]
- How do I Filter Custom Post Type by Custom Taxonomy in the newest WordPress RESTful API?
- get_query_var() not working in pre_get_posts
- Filter for “get_post_type_archive_link()”
- When we register a custom taxonomy or post type, does the WP database modified at all?
- Filter get_categories() for taxonomy term in WordPress
- Ajax filter with custom taxonomies
- Filter posts with ajax form and checkboxes
- Highlight nav menu terms
- Help with issues on “Adding a Taxonomy Filter to Admin List for a Custom Post Type?”
- Want to filter only parent post in admin area
- Creating a function that receives the taxonomy terms that have been changed in a custom post type
- What is better: Custom Fields vs Custom Taxonomies with Terms for perfomance, scalability and better user experience
- Remove “Get Shortlink” button in admin of custom post type
- Custom Taxonomy breaking pages permalinks
- Filter custom post type archive page with custom taxonomies (categories) with AJAX
- Best action hook to create custom post and assign taxonomy terms to it on plugin activation?
- Modifying date filter on admin page for custom post type to link to custom field
- Why is conditionally loading a custom plugin’s code only on a specific custom post type causing the site content to disappear?
- How to query custom post types posts filtered by multiple custom taxonomies through a form selection
- Genesis filterable portfolio isotope [closed]
- How can I see a list of my Custom Post Types of the last term I was in?
- Displaying custom taxonomy in the admin list of a custom post type
- Categories of custom taxonomy don’t show any posts
- WordPress sort search results by custom order
- How to filter wp_list_categories output with some custom post type meta query?
- How to Filter custom post type by taxonomy?
- Filter term taxonomy metabox in custom post type
- How can I made custom taxonomies relationship?
- Limit number of custom posts per taxonomy
- Sort and filter custom post type posts by custom taxonomy
- Filter Posts from the Main Query
- How can I add a filter to a particular post format?
- Is there any way to get list of all possible filter hooks for all post types?
- Filter posts by tax (dropdown) and meta value
- sortable columns for multiple custom post types not working
- Only show posts with a specific term of an associated taxonomy in a custom post type archive
- REST filters only firing when I have a param set
- Custom Taxonomy Filter Issues
- Catch and display error on save_post action
- Custom Permalink For Custom Post Type – Working Fine But Broken For Pagination
- Best way to fix bad count on All | Mine | Published
- In child theme, add CPT to custom taxonomy registered in parent theme
- Changing CPT permalink
- Filter in Custom post type to find the parent post
- Dynamic page for nav items used as filters
- Insert custom taxonomy into category query
- Creating adminable dynamic filtering on custom post type
- Adding Information To All Posts Screen
- Dropdown switching subcategories portfolio
- Filter Content on all Post Types
- Exclude Custom Post Type from shared Custom Taxonomy
- Hook only specific post type
- Change CPT Edit Target Link for Admin List
- Add Custom Taxonomy Terms as CSS Classes for CPT Posts in an Elementor Loop Item Template
- Custom post type template not loading from plugin
- How often do you need to register_post_type?
- Custom query – alternate posts by category
- Need help with complex custom post type setup
- Remove taxonomy slug when not assigning taxonomy with custom post types
- How i add new link after Edit | Quick Edit | Trash | View in quick edit section
- Custom taxonomy template not working with simple loop. Multiple CPT using the same taxonomy
- How loop through posts based on custom fields
- Hierarchical Custom Post Types or Similar
- What is the use of a custom taxonomy?
- wp_query check if integer exists in custom field’s array
- How can I set taxonomy programmatically
- Return the latest post from a custom Taxonomy and Post Type
- Don’t know how to show custom taxonomies from a custom post_type
- list taxonomies from a custom post type
- WordPress custom taxonomy, posts urls
- WordPress loop: Show only a Custom Post Type Taxononmy TERM
- Import data from CSV with custom taxomony empty
- Custom Post Type Loop with Query Var
- Full Custom Post Type List Organised by two Taxonomies
- Template for all categories of a custom post type?
- Custom filter function not working with Custom post type
- How to group posts and get a mixed posts and groups view?
- post_type_link Filter – Too Few Arguments
- Show categories of custom post type and not all posts
- Reusable metabox backend and frontend
- Should i use custom post type for a custom footer?
- Display the link of a custom taxonomy
- Custom taxonomy: on the taxonomy term page show other taxonomy terms
- wp_set_object_terms creates taxonomies but does not add custom posts to it
- How do I Create Single template for custom post type with a custom URL?
- Categories manage
- CPT url rewriting : regular posts return 404 error
- wp_query: How to retrieve current term slug in custom taxonomy?
- tax_query showing no results
- Display posts from category in page
- How to filter posts by categories?
- get tags from custom post type
- Highlight specific menu item when custom post is page
- Output assigned custom taxonomy to custom post type
- Custom Field Search
- Admin user get message higher level of permission to edit taxonomy
- Have Custom Taxonomy Slug Fall Under Custom Post Type Slug
- get total post in category via ajx