Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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' => 1 to the ID of the “kids-videos” category.

    $terms = get_terms(
    
        array(
    
            'taxonomy'   => 'category',
    
            'hide_empty' => true,
    
            'number'     => $per_page,
    
            'offset'     => $offset,
    
            'parent'     => 1
    
        )
    
    );

    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”.

    Hi @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() or WP_Screen::is_block_editor to check whether we’re on the Dashboard doesn’t work here because of the way REST requests work.

    Hi!

    The third parameter of the get_user_meta function specifies whether it should return a single value or an array. And the default for this is false (which returns an array).

    So I believe calling get_user_meta as below should clean up your code.

    $user_meta = get_user_meta( $user_id, 'my_data', true );

    You can learn more about get_user_meta here: https://developer.ww.wp.xz.cn/reference/functions/get_user_meta/

    I 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 $exclusions causes it to stop working. Even if I add the if statement in another function and add it to admin_init and add the filter from there.

    • This reply was modified 5 years, 11 months ago by Thimal Wickremage. Reason: Added more information

    Hey!

    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_script and then immediately loading that script on the next line with wp_enqueue_script. So you’re not loading the “scripts.js” file anywhere on your code.

    You don’t need to use wp_register_script unless you want to have the script registered and then load it elsewhere on your theme with a conditional statement for an example. So, just using wp_enqueue_script to 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.

Viewing 6 replies - 1 through 6 (of 6 total)