Support

Account

Home Forums General Issues ACF Relationship Type Issue

Solving

ACF Relationship Type Issue

  • I’ve inherited a WordPress site from another developer who created a tabbed theme options page. On one the tabs, the admin can select to have a modal pop up with a message, and select which pages they want it to appear on. But right now it’s only working on the page that is first in the selected list:

    select

    This is the field group:

    acf

    I was told that this was working at one time and it suddenly broke. I tested the js, and it’s working fine. And I don’t see any issues with the PHP code. The modal is working fine on the page. It’s just not showing on any of the other selected pages. Anyone have any ideas what is going on?

  • You will need to supply the code that controls outputs the content of this field.

  • Here you go, John. Thanks!

    <?php 
    $spm_display_ids = get_field('spm_display_ids', 'options');
    $id =  get_the_ID(); 
    ?>
    
    @if ($spm_display_ids != null)
      @if (get_field('toggle_sm', 'options') && in_array($id, $spm_display_ids) === true)
        @include('specials-modal')
      @endif
    @endif
  • I have no idea what this coding is, is this some type of templating code?

    
    @if ($spm_display_ids != null)
      @if (get_field('toggle_sm', 'options') && in_array($id, $spm_display_ids) === true)
        @include('specials-modal')
      @endif
    @endif
    

    So I don’t know what this is doing @include('specials-modal') but whatever is doing the outputting is happening in there.

  • It’s done in Laravel. I don’t know much about it, but to me this should be working. I don’t see anything that specifies it only shows on the home page, etc. It’s odd that is was supposedly working and now it’s not.

  • There is no loop in the code that you provided. What you provided only determines that the modal should appear on the current page that is being viewed.

    
    ....
    in_array($id, $spm_display_ids)
    ...
    

    the current page $id is in the array of pages that it should be shown on $spm_display_ids

    If this is true then this line is run

    
    @include('specials-modal')
    

    Exactly what is shown is determined by whatever that includes.

  • I actually put the wrong code up. Here’s the correct code:

    <?php 
    $spm_display_ids = get_field('spm_display_ids', 'options');
    $id =  get_the_ID(); 
    ?>
    
    @if ($spm_display_ids != null)
      @if (get_field('toggle_sm', 'options') && $spm_display_ids[0]->ID == $id)
        @include('specials-modal')
      @endif
    @endif

    The reason it’s not showing up on all pages is because of the spm_display_ids[0]. That means it’s only showing on the first page in the list box. Is there a way to list all of the pages? Ie. [0],[1]…

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

You must be logged in to reply to this topic.