Tagged: 

Viewing 6 reply threads
  • Author
    Posts
    • #3069
      dawood
      Member

      How would I go about creating a repeater field that allows the user to link to a pages?

      I’ve tried a text area that the user can just type the links but seems a page link repeater feild would be more user friendly?

    • #3071
      Steve
      Keymaster

      @dawood– Would a text box, repeater, work? All you need to do is create a standard text field and add: 'add_more' => true

      piklist('field', array(
       'type' => 'text'
       ,'field' => 'field_name'
       ,'label' => 'Example Field'
       ,'description' => 'This is a description of the field.'
       ,'columns' => 12
       ,'add_more' => true
       ));
      
    • #3074
      dawood
      Member

      I that could work, is there anyway to pull in just the link field for the TINY MCE editor so the user can link to any page in their wp site?

    • #3084
      Steve
      Keymaster

      @dawood– You may want to create two text boxes that repeat. One is for the link, and one is the page name. Then put them together in your theme.

    • #3093
      dawood
      Member

      Yeah, that would work, I could just do a standard editor in that case… 🙂

      I normally use Advanced Custom Fields plugin and there’s an option to add a “Page Link” field, and use that fairly often, so was trying to see how I could replicate that …

    • #3101
      Steve
      Keymaster

      @dawood– The code you posted here looks just like the “Page Link” field.

      piklist('field', array(
        'type' => 'select'
        ,'field' => 'dawood'
        ,'columns' => 12
        ,'attributes' => array(
          'multiple' => 'multiple'
        )
        ,'choices' =>  piklist(
                        get_posts(
                           array(
                            'post_type' => 'post'
                            ,'orderby' => 'post_date'
                           )
                           ,'objects'
                         )
                         ,array(
                           'ID'
                           ,'post_title'
                         )
        )
      ));
      

      Since you are setting this field to allow for multiple values selected, you need to loop over the array:

      foreach ($dawood as $key => $value)
      {
        echo '' . get_the_title($value) . '';
      }
      

      The biggest difference here between ACF and Piklist, is that Piklist allows you to use standard WordPress functions like get_permalink() and get_the_title(), while ACF makes you use it’s own functions.

    • #3107
      dawood
      Member

      Thanks Steve that helps!

Viewing 6 reply threads
  • The topic ‘Repeater Link Field’ is closed to new replies.