Support » Plugin: WordPress Page Builder - Beaver Builder » Issue with custom shortcodes

  • Resolved Kokomo

    (@kokomoweb)


    Hi, we are using the astra theme with beaver builder lite. I added a few custom shortcodes to my child theme functions.php and i add the shortcodes to the pages via the beaver builder text editor. The weird thing is that when the shortcodes are added in my functions file, the beaver builder editor doesn’t save my changes and redirects to a random post when i save, without any errors. In order to edit my pages i need to every time comment out the add_shortcode() functions which will be a huge problem when we launch the site and the client will need to do edits himself. Any ideas on why this would happen? I have everything running at the latest version,

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Simon Prosser

    (@pross)

    Exactly what is your shortcode? Thats where the issue probably is.

    Thread Starter Kokomo

    (@kokomoweb)

    function create_infosuisse_table_matiere_shortcode() {
      // Custom WP query query
    
      $output = '';
    
      $args_query = array(
        'post_type' => array('magazine'),
        'posts_per_page' => 1,
        'order' => 'DESC',
      );
    
      $query = new WP_Query( $args_query );
    
      if ( $query->have_posts() ) {
        while ( $query->have_posts() ) {
          $query->the_post();
          $output .= get_field('table_des_matieres');
        }
      } else {
    
      }
      return $output;
    
      wp_reset_postdata();
    
    }
    add_shortcode( 'info-suisse_table_matiere', 'create_infosuisse_table_matiere_shortcode' );
    • This reply was modified 4 months ago by Kokomo.
    Plugin Author Simon Prosser

    (@pross)

    You should probably use get_posts() for a simple query like that but at 1st glance you have wp_reset_postdata() *after* the return $output; line.

    Thread Starter Kokomo

    (@kokomoweb)

    Hi Simon,

    I’ve been reading about wp_reset_postdata() and it seems putting it after is the proper way to do it. I just tried inverting it and then i just cant edit any boxes in the beaver builder anymore

    • This reply was modified 4 months ago by Kokomo.
    Thread Starter Kokomo

    (@kokomoweb)

    @pross, sorry you were right I figured it out! THanks a lot for the help

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.