Get rewrite slug of custom post type in template

You can access the post type properties using get_post_type_object(). The rewrite argument will be a property if the returned object: $post_type_object = get_post_type_object( ‘products’ ); $rewrite_slug = $post_type_object->rewrite[‘slug’]; Update I needed this for permalinks inside a template part where there are categories displayed. No you don’t. To get the URL to a category archive, use … Read more

Custom url for a plugin page add_rewrite_rule WordPress

After a long search finally i found a working solution. I am posting here in case someone face the similar issue, it would be helpful. Here is my working code: add_action(‘template_redirect’, array($this, ‘zip_template’)); add_filter( ‘rewrite_rules_array’, array($this, ‘zip_rule’) ); add_filter( ‘query_vars’, array( $this, ‘zip_query_vars’ ) ); add_action( ‘wp_loaded’, array( $this, ‘flush_rules’ ) ); /** * Rewrite … Read more

Plugin translation not working apart from name and description

Seems like you forgot to load the text domain The plugin handbook says that: You need to load the MO file with your plugin’s translations. You can load them by calling the function load_plugin_textdomain() (and load_muplugin_textdomain() if your plugin will be used as a Must-Use plugin). This call loads {text-domain}-{locale}.mo from your plugin’s base directory. … Read more

add more custom post types and custom role to the code

its better to include your assets with admin_enqueue_scripts for your question add_action(‘admin_head’, ‘grup_custom_admin_post_css’); function grup_custom_admin_post_css() { $allow_post_types = array(‘custom_role’, ‘custom_role_2’, ‘etc’); $allow_roles = array(‘post_type’, ‘post_typ_2’); $current_user = wp_get_current_user(); if (array_intersect($current_user->roles, $allow_roles)) { // do something if user have one of these roles global $post_type; if ($post_type && in_array($post_type, $allow_post_types)) { echo “<style></style>”; } } }

WP_Query ordering numbers as letters

To evaluate a meta value as a number, use meta_value_num. Try: $args = array( “fields” => “ids”, “meta_key” => “jogador_oficial”, “meta_value” => true, “meta_query” => array( “relation” => “AND”, “query_one” => array( “key” => “quantidade_corretas” “orderby” => “meta_value_num”, “order” => “DESC” ), “query_two” => array( “key” => “tempo_total” “orderby” => “meta_value_num”, “order” => “ASC” ), … Read more

How to make a custom field as an editor in wordpress?

Naren, The actual set-up for the classic/TinyMCE editor is relatively straightforward, I have updated your wordpress_register_fields() function with the necessary lines. For wp_editor() to work you need to get the content if there’s any saved, id the field and then provide settings arguments. (https://developer.wordpress.org/reference/functions/wp_editor/) function wordpress_register_fields() { global $post; // Nonce field to validate form … Read more

Initial help with official “create a block” tutorial

Glad that you managed to fix the 3rd issue (block validation failed), and as for the first and second issues, you can fix them by using useBlockProps in your block’s edit callback: // In src/index.js import { TextControl } from ‘@wordpress/components’; import { useBlockProps } from ‘@wordpress/block-editor’; export default function Edit( { attributes, className, setAttributes … Read more