Soumanta Bhowmick
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: Creating metaboxes in loopthe 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.
- This reply was modified 7 years, 6 months ago by Soumanta Bhowmick.
- This reply was modified 7 years, 6 months ago by Soumanta Bhowmick.
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');
Forum: Developing with WordPress
In reply to: Convert cURL to wp_remote_postNot working, already tried.
Forum: Fixing WordPress
In reply to: links not working going to page not foundYou 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.
Forum: Fixing WordPress
In reply to: Cannot see any popups in Admin areaCan you check the browser console if there are any errors?
Forum: Developing with WordPress
In reply to: WP_Editor not working via Ajax Dialogue window“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 thisThe editor can be initialized when needed after page load. See wp.editor.initialize() in wp-admin/js/editor.js for initialization options.