Support

Account

Forum Replies Created

  • Thanks! That was exactly what i was looking for!
    It’s working now!

  • You can do it with ‘ACF-Post Object‘ Field or ‘ACF-Page-link‘ field as well.

  • Let’s say, i have a CPT: ‘Performance’, with a few Custom Fields (also an ACF-Gallery field). I have a single-performance.php, where you can see all the things about a performance (also the element of the ACF-Gallery field).
    I made a page-gallery.php. In the admin site of this, there is an ACF-Relationship Field (with multiple values), where you can choose performances.
    I wrote a code in the page-gallery.php, which displays the Featured Image and the Title of the Performances, which are set in the ACF-Relationship field. Now, the Titles and Images are links to the single-performance.php. My goal is, if they click on a Title/Image, then they see a page, where only the Images of the Performance appears, and not the hole single-performance.php.
    But i have no idea how to do that. I need like one more single-performance.php, which appears different as the first one. I can write the content of it, but i don’t know how to name it, and how to create a link to it.

  • I’m sure that a lot of thing missing from my field to work, but i have no idea what.
    Here is my hole field:

    <?php
    class acf_field_year_n_text extends acf_field{
      var $settings, 
        $defaults;
      function __construct(){
        $this->name = 'year_n_text';
        $this->label = __('Year and text');
        $this->category = __("Content",'acf');
        $this->defaults = array(
          'default_value'  =>  '',
          'formatting'   =>  'br',
        );
        parent::__construct();
        $this->settings = array(
          'path' => apply_filters('acf/helpers/get_path', __FILE__),
          'dir' => apply_filters('acf/helpers/get_dir', __FILE__),
          'version' => '1.0.0'
        );
      }
      function create_options($field){
        $key = $field['name'];
        ?>
        <tr class="field_option field_option_<?php echo $this->name; ?>">
          <td class="label">
            <label><?php _e("Formatting",'acf'); ?></label>
            <p class="description"><?php _e("Define how to render html tags",'acf'); ?></p>
          </td>
          <td>
            <?php 
            do_action('acf/create_field', array(
              'type'  =>  'select',
              'name'  =>  'fields['.$key.'][formatting]',
              'name2'  =>  'fields['.$key.'2][formatting]',
              'value'  =>  $field['formatting'],
              'choices' => array(
                'none'  =>  __("None",'acf'),
                'br'  =>  __("auto <br />",'acf'),
                'html'  =>  __("HTML",'acf'),
              )
            ));
            ?>
          </td>
        </tr>
        <?php
      }
      function create_field( $field ){
        ?>
        <table >
          <tr>
            <th scope="col">Year</th>
            <th scope="col">Text</th>
          </tr>
          <tr>
            <?php var_dump ($field['value']); ?>
            <td>
              <?php echo '<textarea 
                id="' . $field['id'] . '" 
                rows="4" 
                class="' . $field['class'] . '"
                name="' . $field['name']['textarea_1'] . '" >'
                  . $field['value']['textarea_1'] . 
                '</textarea>';
              ?>
            </td>
            <td>
              <?php echo '<textarea 
                id="' . $field['id'] . '" 
                rows="4" 
                class="' . $field['class'] . '"
                name="' . $field['name']['textarea_2'] . '" >'
                  . $field['value']['textarea_2'] . 
                '</textarea>';
              ?>
            </td>
          </tr>
        </table>
        <?php
      }
      function input_admin_enqueue_scripts(){
        wp_register_script('acf-input-year_n_text', $this->settings['dir'] . 'js/input.js', array('acf-input'), $this->settings['version']);
        wp_register_style('acf-input-year_n_text', $this->settings['dir'] . 'css/input.css', array('acf-input'), $this->settings['version']);
        wp_enqueue_script(array(
          'acf-input-year_n_text',
        ));
        wp_enqueue_style(array(
          'acf-input-year_n_text',
        ));
      }
    }
    new acf_field_year_n_text();
    ?>
  • I tried already what you write, and then the HTML result is:

    <textarea id="acf-field-text-year" class="year_n_text" name="f"></textarea>
    <textarea id="acf-field-vita-year" class="year_n_text" name="f"></textarea>
  • Yes, i checked the generated HTML source, and played with a few versions (with brackets, in quotes…), i’m not expert in PHP…
    It still not working, maybe i asked the question wrong.
    So the name of the textarea is how ACF knows which field to save (not the ID or class)? So if i want two textarea, they need to have different names.
    Now the working field has a name: $field[‘name’] which generates: fields[field_51fbdeb7f1609].
    What should i add as a name to the second textarea, and how can i get the value of it?
    I can get the value of the field with the $field[‘value’], but it’s just the value of the textare with the name: $field[‘name’].
    Uhhh, maybe it’s a bit too complicated for me…

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