acf-options-for-polylang icon indicating copy to clipboard operation
acf-options-for-polylang copied to clipboard

Front page fields not visible when activating plugin

Open rollecode opened this issue 7 years ago • 11 comments

Version information

  • Plugin version: 1.1.6 (dev-master)
  • PHP: 7.2.13
  • WordPress: 5.1.1
  • ACF version: 5.7.13
  • Polylang version: Polylang Pro 2.5.3

Steps to reproduce

  1. Activate addon
  2. Go to front page
  3. See empty page

What was expected

Front page fields to be visible.

What happened instead

Front page is empty (the styles load up but no content).

This plugin should not affect normal pages, right? My front page fields are set to be displayed if page type is same as front page (that is selected in general settings) and I have only one repeater on front page.

When var_dumping the field, it returns a string (id, perhaps?). How to proceed?

rollecode avatar Apr 24 '19 13:04 rollecode

Hello @ronilaukkarinen, thx for submitting an issue.

Could you please try using the last stable version instead and tell me if you have the same behaviour ?

Thx

MaximeCulea avatar Apr 24 '19 13:04 MaximeCulea

Yes, the same thing happens on stable version.

For the record, this is my front page code:

<?php
/**
 * The template for displaying front page
 *
 * Contains the closing of the #content div and all content after.
 * Initial styles for front page template.
 *
 * @link https://developer.wordpress.org/themes/basics/template-files/#template-partials
 *
 * @package maskedprefix
 */
get_header();

// Get slider.
$slider = get_field( 'front_hero_slider' );

// Counter for slides
$i = 0;

// Featured image.
$featured_image = '';
if ( has_post_thumbnail() ) :
  $featured_image = wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) );
else :
  $featured_image = get_theme_file_uri( 'images/default.jpg' );
endif;
?>

<div id="content" class="content-area">
  <div id="main" class="site-main">

    <?php if ( ! empty( $slider ) ) : ?>
      <div class="block block-hero block-front-hero slider">
        <div class="slider-wrapper">
          <?php if ( have_rows( 'front_hero_slider' ) ) :
            while ( have_rows( 'front_hero_slider' ) ) :

            // Fields
            $small_title = get_sub_field( 'small_title' );
            $title = get_sub_field( 'title' );
            $content = get_sub_field( 'content' );
            $image = get_sub_field( 'image' );
            ?>
            <div class="slider-slide" style="background-image: url('<?php echo wp_get_attachment_url( $image ); ?>')">
              <div class="shade"></div>
              <div class="container">
                <p><?php echo $small_title; ?></p>
                <h1><?php echo $title; ?></h1>
                <p class="short-description"><?php echo ( $content ); ?></p>
              </div>
            </div>
          <?php endwhile;
          endif; ?>
        </div>
        <div class="slider-navigation">
          <div class="container">
            <div class="slider-navigation-links">
              <?php while ( have_rows( 'front_hero_slider' ) ) : $i++; ?>
                <a href="#" class="slider-navigation-link" data-slider-go="<?php echo $i; ?>"><?php echo$title; ?> <span class="number"><?php echo $i; ?></span></a>
              <?php endwhile; ?>
              <div class="slider-duration-indicator"><div class="slider-duration-indicator-meter"></div></div>
            </div>
          </div>
        </div>
      </div>
    <?php endif;

    get_template_part( 'template-parts/content', 'modular' ); ?>

  </div><!-- #main -->
</div><!-- #primary -->

<?php get_footer();

get_field( 'front_hero_slider' ) displays a string "3" instead of sub fields.

rollecode avatar Apr 24 '19 13:04 rollecode

For the record, seems that I don't need a plugin in my case. My accommodation CPT has an options page so just added 'post_id' => pll_current_language(), like this:

/**
 * Create ACF setting page
 *
 * @since 1.0.0
 */
if ( function_exists( 'acf_add_options_sub_page' ) ) {
  acf_add_options_sub_page(array(
    'title'      => 'Accommodations index',
    'parent'     => 'edit.php?post_type=accommodation',
    'capability' => 'manage_options',
    'post_id'    => pll_current_language(),
  ));
}

So for me personally the issue is resolved. That doesn't remove the bug in the plugin though.

rollecode avatar Apr 24 '19 17:04 rollecode

@MaximeCulea This is the bug with the ACF repeater, I think the patch using the acf_get_value () function fixes the problem described here.

Your opinion ?

See patch : https://github.com/BeAPI/acf-options-for-polylang/commit/e2890a9f3ed6ee8d758e9b3bfcc7bcf97667ceef#diff-030ecddf65a33a47ca1742e763782150L133

herewithme avatar May 09 '19 03:05 herewithme

@ronilaukkarinen can you try the latest development version ? (master)

herewithme avatar May 09 '19 03:05 herewithme

@herewithme don't think it's related, but if it is working with this patch, glad to hear 🤗 Waiting for your test then @ronilaukkarinen 😉 Thank you

MaximeCulea avatar May 10 '19 08:05 MaximeCulea

Just tested it (by reming post_id from here) and enabling plugin. Now getting error on front-page.php

Screenshot

After deactivating everything works. So not fully working for me right now.

We already completed this project with custom coding it, so no real use case to test for me right now.

rollecode avatar May 10 '19 08:05 rollecode

Pity :/ Ok then, if you var_dump() the $slider, what do you get @ronilaukkarinen ? Thx

MaximeCulea avatar May 10 '19 08:05 MaximeCulea

@ronilaukkarinen Thank you for sending us the JSON export (or PHP) used, as well as the function declaring the option page and the template part in question.

herewithme avatar May 10 '19 08:05 herewithme

var_dump( $slider ); prints out:

string(1) "3"

Version is confirmed as 1.1.7 (dev-master) so it seems the problem persists in this version. But as I said we have moved on from this project and I won't have time to debug this further, but I guess you have now all the means for investigating more. We practically have only used flexible fields and repeaters in the front-page and option templates.

rollecode avatar May 10 '19 08:05 rollecode

I tested in all directions. If ever, the problem reoccurs in a new project in the future, thank you to reopen the ticket :)

By the way, in the code given as an example https://github.com/BeAPI/acf-options-for-polylang/issues/45#issuecomment-486242749

There is no second "option" parameter in the initial get_field.

herewithme avatar May 20 '19 12:05 herewithme