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
- wp_dropdown_categories in custom post type with custom taxonomy
- How can I convert a Custom Taxonomy to a Custom Post Type?
- Page to display an archive of taxonomies
- How to make custom posts to behave like taxonomy?
- Should I use custom taxonomy or custom post type
- Custom Post Type doesn’t show Draft and Trash Options
- A question on creating filters for custom posts using taxonomy
- Custom Taxonomy back-end customizations
- WooCommerce sort products by the actual product width(not the shipping width)
- Custom Post Type by Taxonomy
- Assign Custom post to Custom Taxonomy
- How to add custom taxonomy in custom post type permalink?
- What’s the name of the custom post type yearly archive template?
- Combine multiple getEntityRecords calls
- Create an archive page for custom post type with custom taxonomy
- Custom URLs in post types make it impossible to view archive
- Custom Taxonomy Search result page
- Permalink problems with custom post type and custom taxonomy
- Pull in taxonomy field of custom post type in new query
- Use the custom post type archive for taxonomies?
- Custom Post Type Categories URL not displaying posts
- Taxonomy template page not working
- Custom post type subtaxonomy template
- tax_query (if the terms are empty)
- How to count other posts not having specific taxonomy terms?
- List all posts in taxonomy term
- How can I tell if I’m on a custom post type archive page?
- Can’t Get Parent and Child Categories of Custom Taxonomy to Display
- Query for specific taxonomy that executes a particular loop depending on volume of posts?
- Create a Dropdown Selector and Redirect for a Custom Taxonomy in WordPress?
- How to Implement Search Functionality?
- Query filter by value in meta_value array
- Search CPT by tag ids
- Custom post type 404 category page
- Post template with breadcrumb needs to show page navigated from
- Set up Custom Taxonomy Archive Template File To Cover 3 Categories
- Custom Post Type / Taxonomy / Term – what template to use to avoid 404-page?
- Back, Next, and Previous links for the REFERRING term archive
- Query posts by multiple custom fields
- Pagination not working (page/2 retunring 404 page)
- Get category list & taxonomy list from different post type using post id?
- WordPress add taxonomies/terms list as a menu in archive page
- Add different meta box based on taxonomy
- insert a taxonomy for a custom post type