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 to Filter the Custom term loop based on dropdown
- Am unable to reset a query properly
- How to use the post_title of custom post type as taxonomy
- Custom Taxonomy URL are redirecting to page with the same name
- Query/list all terms and their custom post count
- Append date to custom post type url slug
- Custom Post Type Archive Page Filtering
- Root slug of taxonomy returning 404
- How to bulk copy custom fields between custom posts?
- get_attached_media() on author page not working
- Remove url rewrites for registered taxonomies
- Received nothing after executing AJAX post function
- How can I auto-assign a CPT post to category in a custom taxonomy when published?
- Filtering WP_Query Dynamically on the Front-End
- What template files do I need to customise custom-category-term-links rather than fall back on archive.php?
- CPT UI change custom taxonomy url
- wp_get_post_terms on custom post type with custom taxonomies returning an empty array
- Why get_posts() not returning only selected category posts from Custom Post Type?
- Get template part using a custom taxonomy term
- Retrieve value of a category’s custom field
- Custom Post Type / Two level deep taxonomy (cat. and subcat.) uri problem (error 404)
- Archive for custom taxonomy lists all posts instead of current taxonomy
- Adding a custom post type taxonomy template in plugin
- Get post from custom post type order by two taxonomies
- Loading custom content type from ajax results?
- Get posts by querying taxonomy and certain terms of the taxonomy?
- How to restrict users and admin from creating new taxonomy terms?
- Posts from all the categories are being displayed instead of particular category
- How to save custom taxonomy from front end post submission
- How to convert custom post type based list to a dropdown list?
- How to add a custom taxonomy to show up in a custom post type menu?
- Overriding taxonomy and custom post type
- Get next and previous 3 posts in a term in single post page
- wp_query check if integer exists in custom field’s array
- Customize Query for post
- Custom post type templating problem
- Correct classes for WordPress menu items
- Wrong request query on cpt and tax
- Custom Taxonomies not appearing in Admin
- Custom Post hierarchical to custom taxonomy
- Custom Taxonomy Navigation, with current menu items for children?
- Search Custom Post Type & Taxonomies
- Getting a PHP Notice when using Pods with WPML [closed]