• Hi
    Every time I update the content of a post the editor switches immediately to Text mode and doesn’t come back to the Page Builder. I also noticed that the Live Editor feature is not working properly. After deactivating all plugins and changing the theme I found that there is a conflict with the code of a custom widget at the theme, specifically with a custom loop:

    public static function trips_list($listRel) {
    		 global $post;
    	 	 $langua = pll_current_language('locale');
    	 	 $theTrips = !empty($listRel) ? $listRel : array(array());
    		 $args2 = array(
    		                'post_type'         => 'trip',
    		                'post_status'       => 'publish',
    		                'posts_per_page'    =>  -1,
    						'order' => 'ASC'
    		            );
    
    		  $tripQuery2 = new WP_Query( $args2 );
    		  if($tripQuery2->have_posts() ) :?>
    		     <div>Choose the related trips for this post</div><p></p>
         <?php  while ( $tripQuery2->have_posts() ) : 
    
                	$tripQuery2->the_post();?>
                       <li><input type="checkbox" name="trip_list[]" value="<?php echo $post->ID;?>" <?php if(in_array($post->ID, $theTrips[0])){ echo 'checked="checked"';} ?>> <span><?php echo the_title(); ?></span></li>
         <?php  endwhile;
                wp_reset_postdata();
    
    	     endif;
    	}

    Please help me understand why this code is causing these issues

    • This topic was modified 6 years, 9 months ago by little_bird.

    The page I need help with: [log in to see the link]

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor alexgso

    (@alexgso)

    Hi @little_bird,

    Unfortunately, I’m not too sure why this is happening.
    Can you please clarify what theme you’re using?
    Also, does this issue only occur when you’re using this widget on the page or is it happening regardless of its usage?

    Thread Starter little_bird

    (@little_bird)

    Hi Alex

    Thanks for your reply. I am very sorry I’m responding to you message until now, but somehow I didn’t receive the support replies in my email.
    Unfortunately the site is having the same switch at the editor after updating the posts.
    Regarding the site’s theme, it is a custom one I built and the issue occurs with or without the widget on the post pages.

    I forgot to mention that the custom widget I built also adds a metadata box with multiple selection (a list of custom post) at the bottom of the post editor page.

    Thanks for your help.

    • This reply was modified 6 years, 8 months ago by little_bird.
    Plugin Contributor alexgso

    (@alexgso)

    Hi @little_bird,

    Based on your reply and your initial post, I strongly suspect you’re experiencing a PHP or JavaScript error.

    Can you please enable WP_DEBUG which will require editing wp-config.php, if you need help with that I would get in contact with your hosting provider. Do you see any error messages when Page Builder isn’t able to load? If not, please send me the contents of your console. Please refer to this guide on how to access your browser console.

    Thread Starter little_bird

    (@little_bird)

    Hi Alex

    I enabled the WP_DEBUG mode but it didn’t show any PHP error message or warning. At the console in my browser I didn’t see any error from the Page Builder plugin but I discover an error from the Yoast SEO plugin due to a conflict with the Page Builder.
    This is the error at the console:
    wp-seo-post-scraper-703.min.js?ver=7.0.3:13 Error: unable to tokenize
    at Object.end (wp-seo-post-scraper-703.min.js?ver=7.0.3:13)
    at l (wp-seo-post-scraper-703.min.js?ver=7.0.3:1)
    at g (wp-seo-post-scraper-703.min.js?ver=7.0.3:1)
    at n (wp-seo-help-center-703.min.js?ver=7.0.3:6)
    at r (wp-seo-help-center-703.min.js?ver=7.0.3:6)
    at r (wp-seo-post-scraper-703.min.js?ver=7.0.3:1)
    at r (wp-seo-post-scraper-703.min.js?ver=7.0.3:1)
    at e.exports (wp-seo-post-scraper-703.min.js?ver=7.0.3:1)
    at e.exports (wp-seo-post-scraper-703.min.js?ver=7.0.3:13)
    at Object.e.exports [as calculateFleschReading] (wp-seo-post-scraper-703.min.js?ver=7.0.3:13)

    This error appears many times when I used the Image Widget at the Page Builder. When I only use the SiteOrigen Editor widget there isn’t any error message at the console. Anyway, I still have the issue with my widget code and the Page Builder and I pretty sure is something related to the custom WP_Query after hours of debugging, but I can’t why this query is affecting the Page builder performance.

    • This reply was modified 6 years, 8 months ago by little_bird.
    Plugin Contributor alexgso

    (@alexgso)

    Hi Little_bird,

    Unfortunately, the mentioned console error is as a result of how Yoast handles shortcodes – this will likely be corrected in an upcoming Yoast update.

    What happens if you disable Yoast temporarily? I don’t think this will help but that’s the only thing that jumps out as an obvious problem.

    If that doesn’t help, what happens if you remove, or return basic (or no data)? Does this issue remain?

    Thread Starter little_bird

    (@little_bird)

    Hi Alex

    Disabling the Yoast plugin doesn’t solve the switch to text mode at the editor after updating the post.

    I made a test changing the the static function in my widget. The original code is:

    public static function trips_list($listRel) {
    		 global $post;
    	 	 $langua = pll_current_language('locale');
    	 	 $theTrips = !empty($listRel) ? $listRel : array(array());
    		 $args2 = array(
    		                'post_type'         => 'trip',
    		                'post_status'       => 'publish',
    		                'posts_per_page'    =>  -1,
    						'order' => 'ASC'
    		            );
    
    		  $tripQuery2 = new WP_Query( $args2 );
    		  if($tripQuery2->have_posts() ) :?>
    		     <div>Choose the related trips for this post</div><p></p>
         <?php  while ( $tripQuery2->have_posts() ) : 
    
                	$tripQuery2->the_post();?>
                       <li><input type="checkbox" name="trip_list[]" value="<?php echo $post->ID;?>" <?php if(in_array($post->ID, $theTrips[0])){ echo 'checked="checked"';} ?>> <span><?php echo the_title(); ?></span></li>
         <?php  endwhile;
                wp_reset_postdata();
    
    	     endif;
    	}

    I removed the loop and changed it for a simple input field

    public static function trips_list($listRel) {
    		 global $post;
    	 	 $langua = pll_current_language('locale');
    	 	 $theTrips = !empty($listRel) ? $listRel : array(array());
    		 $args2 = array(
    		                'post_type'         => 'trip',
    		                'post_status'       => 'publish',
    		                'posts_per_page'    =>  -1,
    						'order' => 'ASC'
    		            );
    
    		  $tripQuery2 = new WP_Query( $args2 );
    		 ?> 
    		     <div>Choose the related trips for this post</div><p></p>
                	
                       <li><input type="checkbox" name="trip_list[]" value="67"> <span>One single trip</span></li>
       
          <?php
            wp_reset_postdata();
    	     
    	}
    }

    Removing the loop at the widget code solved the issue of the Page builder editor!!
    I don’t understand at all why this loop is affecting the Page builder behavior.

    Do you have any idea?

    Plugin Contributor alexgso

    (@alexgso)

    Hi Little_bird,

    To be honest, we’re not too sure why that code may have been affecting SiteOrigin Page Builder. Can you please the usage and context of your code? This should hopefully allow me to work out why this code is being incorrectly picked up.

    Thread Starter little_bird

    (@little_bird)

    Hi Alex

    At the theme I created a custom post called Trips. At the regular post page of the blog, in the sidebar, there is a widget where appear the Trips related to that post (if the author chooses any). You can see an example in this post:
    https://site4.sirius-web.net/jerusalem-center-world/

    At the post editor, there is a metabox with the list of all the Trips for the author to choose if any is related to the post content.

    At the functions.php of the theme I created a class for the Related Trips and also I created the widget extending the WP_Widget class.

    Do you need more details of the code?

    Plugin Contributor alexgso

    (@alexgso)

    Hi Little_bird,

    Ideally, yes. Do you have a GitHub or anything that where we can see the code that relates to the problematic code? Sorry about this!

    Thread Starter little_bird

    (@little_bird)

    Hi Alex

    This is the widget code. It’s not too long

    class Jeru_Reltrips{
    
    	protected static $_instance = null;
    
    	protected function __construct() {
    		$this->init();	
    	}
    
    	public static function laInstancia() {
            if(is_null(self::$_instance)) {
            	self::$_instance = new self();
            }
            return self::$_instance;
    	}
    
    	public static function add_the_meta_box() {
    		add_meta_box( 'jeru_selec_trips', __( 'Related Trips in Post', 'jeruthalem' ), array('Jeru_Reltrips','display_meta_post_edit'), 'post', 'normal', 'default' );
    	}
    
    	public function init() {
    		add_action('add_meta_boxes', array('Jeru_Reltrips', 'add_the_meta_box'),10,2);
    		add_action( 'save_post',  array('Jeru_Reltrips', 'save_meta_data') );
    		add_action( 'widgets_init', function(){ register_widget( 'Jeru_Reltrips_Widget' );});
    	}
    
    	public static function display_meta_post_edit() {
    		global $post;
    		$jeru_reltrips = get_post_meta($post->ID, 'jeru_reltrips');
    		//echo "<pre>".var_dump($jeru_reltrips)."</pre>";
    		self::trips_list($jeru_reltrips);
    	}
    
    	public static function save_meta_data( $post_id ) {
    		if(isset($_POST['trip_list'])){
    			$cleanData = array();
    			foreach($_POST['trip_list'] as $val){
                    $cleanData[] = filter_var( $val, FILTER_SANITIZE_NUMBER_INT );
    			}
    
    			update_post_meta( $post_id, 'jeru_reltrips', $cleanData);
    		}else
    
    		delete_post_meta( $post_id, 'jeru_reltrips' );
    	}
    
    	public static function trips_list($listRel) {
    		 global $post;
    	 	 $langua = pll_current_language('locale');
    	 	 $theTrips = !empty($listRel) ? $listRel : array(array());
    		 $args2 = array(
    		                'post_type'         => 'trip',
    		                'post_status'       => 'publish',
    		                'posts_per_page'    =>  -1,
    						'order' => 'ASC'
    		            );
    
    		  $tripQuery2 = new WP_Query( $args2 );
    		  if($tripQuery2->have_posts() ) :?>
    		     <div>Choose the related trips for this post</div><p></p>
         <?php  while ( $tripQuery2->have_posts() ) : 
    
                	$tripQuery2->the_post();?>
                       <li><input type="checkbox" name="trip_list[]" value="<?php echo $post->ID;?>" <?php if(in_array($post->ID, $theTrips[0])){ echo 'checked="checked"';} ?>> <span><?php echo the_title(); ?></span></li>
         <?php  endwhile;
                wp_reset_postdata();
    
    	     endif;
    	}
    }
    
    class Jeru_Reltrips_Widget extends WP_Widget {
    
    	function __construct() {
               parent::__construct(
    			'related_trips_widget',
    			'Related Trips Widget',
    			array( 'description' => 'Display related trips in the sidebar' )
    		);
    	}
    
    	public function widget( $args, $instance ) {
    		if(!is_single()) {
    			return;
    		}
    		global $post;
    		$jeru_reltrips = get_post_meta($post->ID, 'jeru_reltrips');
    
    		$title  = isset( $instance['title'] ) ? $instance['title'] : '';
    
    		$title = ( ! empty( $instance['title'] ) ) ? $instance['title'] : __( 'Related Trips','jeruthalem' );
    
    		$title = apply_filters( 'widget_title', $title, $instance, $this->id_base );
    
    		if(!empty($jeru_reltrips)){
    			echo $args['before_widget'];
    			 if ( $title ) {
    				echo $args['before_title'] . $title . $args['after_title'];
    			}
    			echo '<div id="only_related">';
    			$this->selected_trips_post($jeru_reltrips);
    			echo '</div>';
    			echo $args['after_widget'];
    		}
    	}
    
    	public function form( $instance ) {
    		$title     = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : '';
    		?>
    		<p><label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
    		<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo $title; ?>" /></p>
    
    	   <?php
    	}
    
    	public function update( $new_instance, $old_instance ) {
    		$instance = $old_instance;
    		$instance['title'] = sanitize_text_field( $new_instance['title'] );
    		return $instance;
    	}
    
    	private function selected_trips_post($trips_ids) {
           global $post;
           $langua = pll_current_language('locale');
    	 	  $moreD = '';
    	 	  if($langua==='en_US'):
    			   $moreD = 'More details';
    		  else:
    			   $moreD = '????? ??????';
    	      endif;
    
           $the_ids = array_map('intval', $trips_ids[0]);
           $args3 = array(
    		                'post_type'         => 'trip',
    		                'post__in'          => $the_ids,
    		                'post_status'       => 'publish',
    						'order' => 'ASC'
    		            );
    
    		  $tripQuery3 = new WP_Query( $args3 );
    		  if($tripQuery3->have_posts() ) :
                while ( $tripQuery3->have_posts() ) : 
                     $tripQuery3->the_post();?>
                	<div class="tripWrap clear">
                    	<div class="tripContent">
                    		<div class="tripPic">	
                    			<?php  echo wp_get_attachment_image( get_post_meta( $post->ID, '_jerutometas_trippic_id', 1 ), 'trip-thumb' );
                    			?>
                    		</div> <!-- tripPic -->
                    		<div class="tripText">
                    			<div class="tripTitle">
                                   <a href="" data-izimodal-open="#mod-<?php echo $post->ID;?>" class="modTri" data-izimodal-group="trips"><?php echo the_title();?></a>
                    			</div>
                    			<div class="tripDetails">
                    				<a href="" data-izimodal-open="#mod-<?php echo $post->ID;?>" class="modTri" data-izimodal-group="trips"><?php echo get_post_meta($post->ID, '_jerutometas_tripexce', true);?></a>
                    				<div class="moreDetails"><a href=""><?php echo $moreD;?></a></div>
                    			</div>
                    		</div> <!-- tripText -->
                    	</div> <!-- tripContent -->
                    	<div id="mod-<?php echo $post->ID;?>" class="jerupop" data-izimodal-title="<?php echo the_title();?>">
    	                	
    	                	<div class="modCon">
    	                		<div class="tripDetails">
    	                				<?php echo get_post_meta($post->ID, '_jerutometas_tripdesc', true);?>
    	                		</div>
    	                	</div> <!-- modCon -->
    	                </div> <!-- jerupop -->
    
                    </div> <!-- tripWrap -->
          <?php    endwhile;
                wp_reset_postdata();
    
    	     endif;
    	}
    	
    
    }
    
    Jeru_Reltrips::laInstancia();
    
    • This reply was modified 6 years, 8 months ago by little_bird.
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Editor switches to Text after updating’ is closed to new replies.