Forum Replies Created

Viewing 6 replies - 46 through 51 (of 51 total)
  • the function declaration says,

    add_meta_box( string $id, string $title, callable $callback, string|array|WP_Screen $screen = null, string $context = 'advanced', string $priority = 'default', array $callback_args = null )

    Notice the last parameter $callback_args. You can pass an array as callback args.

    function rttk_create_boxes(){
    	$myarray = $this->rttk_get_posttype_array();
    	foreach ($myarray as $key => $value) {
    		add_meta_box(
    			'rttk_'.$key.'_id', //assuming each key is different
    			__( 'Details', 'rara-theme-toolkit-pro' ),
    			array($this,'rttk_testimonials_metabox_callback'),
    			$screen, // WP_Screen
    			'side',
    			'high',
    			array('key' => $key), // This is what you need
    		);
    	}
    }
    
    public function rttk_testimonials_metabox_callback( $post, $callback_args ){
    	$key = $callback_args['args']['key'];
    	include RTTKPRO_BASE_PATH.'/includes/meta-parts/rttk-'.$key.'-template.php';
    }
    

    See if this is working.

    You need to remove “save_post” hook before updating or adding meta.

    // opens the function
    function updateNumbers( $post_id ){
    
    //* Checks if the post is new or updated, if post is being updated then it skips
    if ( ! wp_is_post_revision( $post_id ) ){
    
    // global wordpress database parameters and only counts posts that are published and in the 'post' CPT
    global $wpdb;
    $querystr = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE
    $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' ";
    $pageposts = $wpdb->get_results($querystr, OBJECT);
    
    // sets the counter at zero
    $counts = 0 ;
    
    // starts the loop, gets and counts how many posts are published
    if ($pageposts):
    foreach ($pageposts as $post):
    $counts++;
    
    // DO IT HERE
    // unhook this function so it doesn't loop infinitely
    remove_action('save_post', 'updateNumbers');
    
    // sets the number in the custom field 'incr_number'
    add_post_meta($post->ID, 'incr_number', $counts, true);
    update_post_meta($post->ID, 'incr_number', $counts);
    
    // INSTEAD OF HERE
    // unhook this function so it doesn't loop infinitely
    // remove_action('save_post', 'updateNumbers');
    
    // update the post using the custom field in the slug, which calls save_post again
    wp_update_post(array('ID' => $post->ID,'post_name' => get_post_meta($post->ID,'incr_number', true)));
    
    // re-hook this function
    add_action('save_post', 'updateNumbers');
    
    // close the loop
    endforeach;
    endif;
    
    // close the function and the 'if' post is an update
    }}
    
    // hooks into the save_post process
    add_action('save_post', 'updateNumbers');
    Thread Starter Soumanta Bhowmick

    (@soumanta)

    Not working, already tried.

    You should not use this kind of links.( i.e. ends with an extension .html,.php etc )

    WordPress provides pretty url structures which can be set from Backend.(WP-Admin Dashboard) see this

    In your case the link
    https://fitnessandkids.com/art_family-fitness.html
    need to be changed to
    https://fitnessandkids.com/art_family-fitness
    or
    https://fitnessandkids.com/art_family-fitness/

    Let me know if this fixed your problem.

    Can you check the browser console if there are any errors?

    “wp_editor()” function implicitly enqueues “wp-admin/js/editor.js” when called from an non-ajax page (pageload).

    In your case, I think the editor.js is not enqueued properly.
    You can also enqueue the “editor.js” explicitly by calling “wp_enqueue_editor()” function. see this

    The editor can be initialized when needed after page load. See wp.editor.initialize() in wp-admin/js/editor.js for initialization options.

Viewing 6 replies - 46 through 51 (of 51 total)