Can one create multiple Custom Post Types with a for loop?

You have a problem with scopes in your code and you misuse actions, I guess. Let me explain… Let’s take a look at this part of code: for($i =1; $i <= $options_foo[‘num_post_types’]; $i++) { global $options_foo; $singular = $options_foo[‘post_type_names’][$i][‘singular’]; $plural = $options_foo[‘post_type_names’][$i][‘plural’]; add_action(‘init’, function(){ global $singular; What it does, is: You loop through all options … Read more

Remove the first 5 characters of the_title and orderby that

WordPress WP_Query’s orderby parameter has a lot of options but nothing as specific as what you are after. I think you’d have to do this after retrieving posts through the WP_Query, then sort them using usort(). Your code should be something like this. $args = array( ‘post_type’ => ‘z_day’, ‘posts_per_page’ => -1, ‘meta_query’ => array( … Read more

Add_menu_page not displaying the menu in class based plugin

There’s a spelling error on the $capability parameter: $cabability = ‘manage_options’; Here’s the working code for the sake of completeness: class Cosmo_Games { public function __construct() { add_action(‘admin_menu’, array($this, ‘create_plugin_settings_page’)); } public function create_plugin_settings_page() { $page_title=”Game Settings”; $menu_title=”Games Plugin”; $capability = ‘manage_options’; $slug = ‘cg_settings’; $callback = array($this, ‘plugin_settings_page_content’); $icon = ‘dashicons-admin-plugins’; $position = 100; … Read more

How to use $_GET function WordPress backend

Working in the admin is quite a bit different from the front-end of a WordPress site. Most of the documentation you’ll find online deals solely with the front-end. That can be frustrating when looking for something that should be simple and straightforward. In this case, I think you would use get_current_screen(). This returns the screen’s … Read more