Support

Account

Home Forums General Issues Custom fields disappear after using shortcode

Solved

Custom fields disappear after using shortcode

  • I created few wysiwyg editors (5 to be exact) inside a page using ACF, and these custom wysiwyg editors only show up when I switch to a new page template call custom-page (switch using the page attributes from default WordPress).

    Here is the problem, I just noticed that whenever I include a shortcode that involves creating a custom loop using wp_Query, it messes up the other wysiwyg editors by not showing in the front end.

    For example:
    In my 2nd wysiwyg editor I use a shortcode call [custom-slider], which will retrieve all my fields from a slider custom post type and display them into front end.
    The slider and the shortcode works but the remaining contents from 3rd, 4th and 5th wysiwyg editors disappears on front end. If I call the shortcode in the 4th editors then only the 5th editor refuses to load (1-4 load perfectly).

    I’ve tried switching from wysiwyg to text field and repeater as well but still doesn’t work.

    I really need a workaround to this urgently as I’m rushing deadline for my client…. Thanks for any help in advance.

    Here is the custom loop I’m using within my shortcode:

    
    $temp = $wp_query;
    
    $args=array(
    'post_status' => 'publish',
    'post_type' => 'new_slider',
    'paged' => $paged,
    'p' => 2 //only retrieve content from this post
    );	
    $wp_query = new WP_Query($args);
    ?>
    <?php
    while ($wp_query->have_posts()) : $wp_query->the_post();
    $do_not_duplicate = $post->ID;
    ?>
    
    ....loop content here
    
     
    <?php endwhile;  ?>
        
    <?php 
    $wp_query = null; $wp_query = $temp;
    
  • try this

    drop this lines:

    $temp = $wp_query; 
    $wp_query = null; $wp_query = $temp;

    and use this to reset query
    wp_reset_query();

  • YES!!! it works, I placed it at the end of my shortcode and everything magically show up again. Mind telling me how wp_reset_query(); solve the issue?

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Custom fields disappear after using shortcode’ is closed to new replies.