Forum Replies Created

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter gseurope

    (@gseurope)

    Hi,

    I deleted the level 7 user and created a new one, cloning the administrator features, a role with level 10 and still not working …

    I have cleared the browser cache, I have also disabled a maintenance plugin, I have generated a new htacces file, and I have rebuilt the premalinks and it still does not work …

    Thread Starter gseurope

    (@gseurope)

    Hi,

    Thanks for your coments.
    I have unsubscribed this user and created a new one, this one has the same permissions including the write one, but when I try to login, it redirects me to the about us page.

    Actually I have these users:
    Collaborator – Level 0 – With read permissions – It works correctly, I can enter the Dashboard
    Mentor – Level 7 – With read permissions – It works correctly, I can enter the Dashboard
    Admin – Level 10 – With read permissions – Works correctly
    Designer – Level 8 – With read permissions – Does not work, even if I raise it up to level 10 …

    I don’t understand why…
    What do you think about this issue?

    Thread Starter gseurope

    (@gseurope)

    Hi,

    It’s possible that your plgin doesn’t translate the values of Custom Post Types?

    Thanks!

    Thread Starter gseurope

    (@gseurope)

    Hi!

    any solution for this?

    Thanks!

    Thread Starter gseurope

    (@gseurope)

    Hi,

    It works perfect now!
    Thanks!

    Thread Starter gseurope

    (@gseurope)

    Hello,

    Thanks again.
    I have reviewed your code and I see that the add_meta_box poses it differently than I do.

    I have tested your code and the custom fields of the back office disappear…i dont’ undestant why.

    On the other hand, all the developed code, I implement it in the functions.php file of my theme Recycle (Premium)

    This is the full code that i use for develop this funcionality:

    if ( ! function_exists('learning_tools_cpt') ) {
    
    // Creem la funció del Custom Post Type Learning Tools
    function learning_tools_cpt() {
    
    	$labels = array(
    		'name'                  => _x( 'Learning Tools', 'Post Type General Name', 'learning_tools_domain' ),
    		'singular_name'         => _x( 'Learning Tool', 'Post Type Singular Name', 'learning_tools_domain' ),
    		'menu_name'             => __( 'Learning Tools', 'learning_tools_domain' ),
    		'name_admin_bar'        => __( 'Learning Tools', 'learning_tools_domain' ),
    		'archives'              => __( 'Learning Tools Archives', 'learning_tools_domain' ),
    		'attributes'            => __( 'Learning Tool Attributes', 'learning_tools_domain' ),
    		'parent_item_colon'     => __( 'Parent Learning Tool:', 'learning_tools_domain' ),
    		'all_items'             => __( 'All Learning Tools', 'learning_tools_domain' ),
    		'add_new_item'          => __( 'Add New Learning Tool', 'learning_tools_domain' ),
    		'add_new'               => __( 'Add New', 'learning_tools_domain' ),
    		'new_item'              => __( 'New Learning Tool', 'learning_tools_domain' ),
    		'edit_item'             => __( 'Edit Learning Tool', 'learning_tools_domain' ),
    		'update_item'           => __( 'Update Learning Tool', 'learning_tools_domain' ),
    		'view_item'             => __( 'View Learning Tool', 'learning_tools_domain' ),
    		'view_items'            => __( 'View Learning Tools', 'learning_tools_domain' ),
    		'search_items'          => __( 'Search Learning Tool', 'learning_tools_domain' ),
    		'not_found'             => __( 'Not found', 'learning_tools_domain' ),
    		'not_found_in_trash'    => __( 'Not found in Trash', 'learning_tools_domain' ),
    		'featured_image'        => __( 'Featured Image', 'learning_tools_domain' ),
    		'set_featured_image'    => __( 'Set featured image', 'learning_tools_domain' ),
    		'remove_featured_image' => __( 'Remove featured image', 'learning_tools_domain' ),
    		'use_featured_image'    => __( 'Use as featured image', 'learning_tools_domain' ),
    		'insert_into_item'      => __( 'Insert into Learning Tool', 'learning_tools_domain' ),
    		'uploaded_to_this_item' => __( 'Uploaded to this Learning Tool', 'learning_tools_domain' ),
    		'items_list'            => __( 'Learning Tools list', 'learning_tools_domain' ),
    		'items_list_navigation' => __( 'Learning Tools list navigation', 'learning_tools_domain' ),
    		'filter_items_list'     => __( 'Filter Learning Tools list', 'learning_tools_domain' ),
    	);
    	$rewrite = array(
    		'slug'                  => 'learning-tools',
    		'with_front'            => true,
    		'pages'                 => true,
    		'feeds'                 => true,
    	);
    	$args = array(
    		'label'                 => __( 'Learning Tool', 'learning_tools_domain' ),
    		'description'           => __( 'Learning Tools For Entrepreneurs', 'learning_tools_domain' ),
    		'labels'                => $labels,
    		'supports'              => array( 'title', 'editor', 'thumbnail', 'comments', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes', 'post-formats' ),
    		'taxonomies'            => array( 'category', 'post_tag' ),
    		'hierarchical'          => false,
    		'public'                => true,
    		'show_ui'               => true,
    		'show_in_menu'          => true,
    		'menu_position'         => 25,
    		'menu_icon'             => 'dashicons-paperclip',
    		'show_in_admin_bar'     => true,
    		'show_in_nav_menus'     => true,
    		'can_export'            => true,
    		'has_archive'           => true,
    		'exclude_from_search'   => false,
    		'publicly_queryable'    => true,
    		'rewrite'               => $rewrite,
    		'capability_type'       => 'post',
    	);
    	register_post_type( 'Learning Tools', $args );
    
    }
    add_action( 'init', 'learning_tools_cpt', 0 );
    
    }
    
    function learning_tools_meta_boxes() {
        //add_meta_box($id, $title, $callback, $screen, $context, $priority, $callback_args);
        //add_meta_box('learning_tools',  __('Learning Tools'), 'learning_tools_output_meta_box', 'learning_tools_cpt', 'side', 'high');
          add_meta_box('learning_tools',  __('Learning Tools'), 'learning_tools_output_meta_box', 'Learning Tools', 'normal', 'high');
    }
    add_action('add_meta_boxes', 'learning_tools_meta_boxes');
    
    function learning_tools_output_meta_box($post) {
    
        $learning_tools_date = get_post_meta($post->ID, '_learning_tools_date', true);
        $learning_tools_hour = get_post_meta($post->ID, '_learning_tools_hour', true);
        $learning_tools_duration = get_post_meta($post->ID, '_learning_tools_duration', true);
        $learning_tools_language = get_post_meta($post->ID, '_learning_tools_language', true);
        $learning_tools_modality = get_post_meta($post->ID, '_learning_tools_modality', true);
    
        // Usaremos este nonce field más adelante cuando guardemos en learning_tools_save_meta_box()
            wp_nonce_field( 'save_learning_tools', 'learning_tools_nonce' );
    
        // Date
        echo('<label for="learning_tools_date">' . __('Date', 'text_domain') . '</label> ');
        echo('<input type="date" name="learning_tools_date" id="learning_tools_date" value= "'.$learning_tools_date.'"><br><br>');
    
        // Hour
        echo('<label for="learning_tools_hour">' . __('Hour', 'text_domain') . '</label> ');
        echo('<input type="time" name="learning_tools_hour" id="learning_tools_hour" value=""><br><br>');
    
        // Duration
        echo('<label for="learning_tools_duration">' . __('Duration', 'text_domain') . '</label> ');
        echo('<input type="number" name="learning_tools_duration" id="learning_tools_duration" value=""> h <br><br>');
    
        // Language
        echo('<label for="learning_tools_language">' . __('Language: ', 'text_domain') . '</label> ');
    
        echo('<label for="learning_tools_english">' . __('English ', 'text_domain') . '</label> ');
        echo('<input type="checkbox" name="learning_tools_english" id="learning_tools_english" value="">');
    
        echo('<label for="learning_tools_german">' . __('German ', 'text_domain') . '</label> ');
        echo('<input type="checkbox" name="learning_tools_german" id="learning_tools_german" value="">');
    
        echo('<label for="learning_tools_italian">' . __('Italian ', 'text_domain') . '</label> ');
        echo('<input type="checkbox" name="learning_tools_italian" id="learning_tools_italian" value=""><br><br>');
    
        // Modality
        echo('<label for="learning_tools_modality">' . __('Modality ', 'text_domain') . '</label> ');
        echo('<select name="learning_tools_modality" id="learning_tools_modality"><br><br>');
        echo('<option value="Online">' .__( 'Online', 'learning_tools_textdomain' ).'</option>');
        echo('<option value="On-site">' .__( 'On-site', 'learning_tools_textdomain' ).'</option>');
        echo('</select>');
    }
    
    function learning_tools_save_meta_boxes( $post_id ) {
    
        if(!isset($_POST['learning_tools_nonce']) || ! wp_verify_nonce($_POST['learning_tools_nonce'], 'save_learning_tools')) {
                    return $post_id;
            }
    
        if ( 'learning_tools_cpt' != $_POST['post_type'] ) {
            return $post_id;
        }
    
        if ( ! current_user_can( 'edit_post', $post_id ) ) {
            return $post_id;
        }
    
        $learning_tools_date = $_POST['learning_tools_date'];
        update_post_meta ($post_id, '_learning_tools_date', $learning_tools_date );
    
    return true;
    }
    add_action('save_post', 'learning_tools_save_meta_boxes');

    Thank you very much for the patience and your help.
    Cheers,

    Thread Starter gseurope

    (@gseurope)

    Hi,

    I checked the database and the date still does not appear, in fact I have created a new post and in the database I only get one row and it’s a post that I created since 3 days ago. Tha value of this meta is NULL into the row that i can see.

    I am somewhat confused because the code does not finish working and prevents me from seeing the date in the Back Office and in the Database.

    This are the modifications that I done.
    Modify input echo from output meta box function:

    echo('<label for="learning_tools_date">' . __('Date', 'text_domain') . '</label> ');
        echo('<input type="date" name="learning_tools_date" id="learning_tools_date" value= "'.$learning_tools_date.'"><br><br>');

    Modify content in the function for save meta boxes:

    function learning_tools_save_meta_boxes( $post_id ) {
    
        if(!isset($_POST['learning_tools_nonce']) || ! wp_verify_nonce($_POST['learning_tools_nonce'], 'save_learning_tools')) {
    		return $post_id;
    	}
     
        if ( 'learning_tools_cpt' != $_POST['post_type'] ) {
            return $post_id;
        }
     
        if ( ! current_user_can( 'edit_post', $post_id ) ) {
            return $post_id;
        }
     
        $learning_tools_date = $_POST['learning_tools_date'];
        update_post_meta ($post_id, '_learning_tools_date', $learning_tools_date );
    
    return true;
    }
    add_action('save_post', 'learning_tools_save_meta_boxes');

    Any suggestion or something you think I’m doing wrong?
    Thank you very much again

    Thread Starter gseurope

    (@gseurope)

    Hello,

    Thank you for your comments!
    I have the modifications what you tell me in the first part because it wasn’t correct as I had it.

    Furthermore I have modified the part of the code that you tell me about the input type value, but still it still does not store nothing in the Database.

    To check-I do the following query in the database:
    SELECT P.ID, P.post_title, M.meta_key, M.meta_value FROM wp_posts AS P INNER JOIN wp_postmeta AS M ON M.post_id = P.ID WHERE P.post_type = 'learning_tools' and P.post_status = 'publish' ORDER BY post_title, meta_key

    On the other hand, my custom post type is called learning_tools_cpt and it is used to add information about courses. (course day, start hour, time, language, and online or on-site modality)

    Thanks!

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