Thimal Wickremage
Forum Replies Created
-
Hello!
To get a list of sub categories within the “kids-videos” category, you should be able to use
get_terms()as below. Replace the number 1 in'parent' => 1to the ID of the “kids-videos” category.$terms = get_terms( array( 'taxonomy' => 'category', 'hide_empty' => true, 'number' => $per_page, 'offset' => $offset, 'parent' => 1 ) );Forum: Fixing WordPress
In reply to: Shortcodes in classic block?Hi,
I personally haven’t run into the issue where the classic block doesn’t parse shortcodes. It all worked as expected for me when I did the transition.
For the question about converting the classic blocks to Gutenberg blocks, if it’s only a handful of posts/pages that needs converting, you can convert it on the editor itself. Just select the classic block and click on the “More options” button (the three dots) that pops up just above it and select “Convert to Blocks”.
Forum: Developing with WordPress
In reply to: Hide Some Categories in Post EditorHi @sumon1068
I finally got this working, but it’s not an ideal solution. To remove the categories only from the editor after making the revision bcworkz suggested, you can change the first if statement to this:
if ( defined( 'REST_REQUEST' ) && REST_REQUEST && !current_user_can( 'manage_options' ) ) {This is not an ideal solution because we’re hiding the categories on all REST requests without checking whether it’s on the WordPress Dashboard or not. But as long as your theme isn’t using REST requests to display categories on the front-end, this should work. And maybe someone will come up with a better solution.
Also, methods like
is_admin()orWP_Screen::is_block_editorto check whether we’re on the Dashboard doesn’t work here because of the way REST requests work.Forum: Developing with WordPress
In reply to: get_user_meta with an array of dataHi!
The third parameter of the
get_user_metafunction specifies whether it should return a single value or an array. And the default for this isfalse(which returns an array).So I believe calling
get_user_metaas below should clean up your code.$user_meta = get_user_meta( $user_id, 'my_data', true );You can learn more about
get_user_metahere: https://developer.ww.wp.xz.cn/reference/functions/get_user_meta/Forum: Developing with WordPress
In reply to: Hide Some Categories in Post EditorI believe the plug-in mentioned by @bizanimesh doesn’t filter categories on the WordPress Dashboard. It only works on the front-end. Please correct me if I’m wrong though.
I was looking into the code provided by @sumon1068 on your original post for a few hours now. And from what I found, it and the other plug-ins that you mentioned doesn’t work on Gutenberg.
For some reason, it starts working if I remove the if condition and have it as follows:
add_filter( 'list_terms_exclusions', 'yoursite_list_terms_exclusions', 10, 2 ); function yoursite_list_terms_exclusions( $exclusions, $args ) { return $exclusions . " AND t.slug NOT IN ( 'selected', 'editorial' )"; }But this removes the categories from the front-end as well. So I haven’t really found a solution for Gutenberg yet.
Just wanted to post my findings.
Edit: Adding an if statement anywhere on the code before changing the
$exclusionscauses it to stop working. Even if I add the if statement in another function and add it toadmin_initand add the filter from there.- This reply was modified 5 years, 11 months ago by Thimal Wickremage. Reason: Added more information
Forum: Developing with WordPress
In reply to: JS File not running the scriptHey!
If I’ve read your code right, I believe you’re registering a script named “scripts” which has the source file “blog-scripts.js” with
wp_register_scriptand then immediately loading that script on the next line withwp_enqueue_script. So you’re not loading the “scripts.js” file anywhere on your code.You don’t need to use
wp_register_scriptunless you want to have the script registered and then load it elsewhere on your theme with a conditional statement for an example. So, just usingwp_enqueue_scriptto load both the files as below should fix this.wp_enqueue_script('blog-scripts', get_template_directory_uri().'/blog-scripts.js',array(),false, true); wp_enqueue_script('main-scripts', get_template_directory_uri().'/scripts.js', array(), microtime(), true);On an unrelated note, I’d also recommend not using
microtime()for the script version and instead defining a constant somewhere in your “functions.php” file and using that.