Skip to content

Instantly share code, notes, and snippets.

@jessedmatlock
Forked from kisabelle/acf.php
Created March 26, 2021 13:42
Show Gist options
  • Select an option

  • Save jessedmatlock/57ee59dbb7fcbbe658c8d695db5ccb9d to your computer and use it in GitHub Desktop.

Select an option

Save jessedmatlock/57ee59dbb7fcbbe658c8d695db5ccb9d to your computer and use it in GitHub Desktop.

Revisions

  1. @kisabelle kisabelle revised this gist Mar 16, 2015. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions acf.php
    Original file line number Diff line number Diff line change
    @@ -21,8 +21,9 @@

    <?php if(get_field('logo')): ?>
    <?php
    $attachment_id = get_field('logo');
    $image_attributes = wp_get_attachment_image_src( $attachment_id );
    $attachment_id = get_field('logo');
    $size = 'large';
    $image_attributes = wp_get_attachment_image_src( $attachment_id, $size );
    // [0] => url
    // [1] => width
    // [2] => height
  2. @kisabelle kisabelle revised this gist Mar 16, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion acf.php
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@
    // [0] => url
    // [1] => width
    // [2] => height
    // [3] => boolean: true if $url is a resized image, false if it is the original or if no image is available.
    // [3] => boolean: true if $url is a resized image, false if it isn't or no img avail.
    ?>
    <?php endif; ?>

  3. @kisabelle kisabelle revised this gist Mar 16, 2015. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions acf.php
    Original file line number Diff line number Diff line change
    @@ -23,10 +23,10 @@
    <?php
    $attachment_id = get_field('logo');
    $image_attributes = wp_get_attachment_image_src( $attachment_id );
    // [0] => url
    // [1] => width
    // [2] => height
    // [3] => boolean: true if $url is a resized image, false if it is the original or if no image is available.
    // [0] => url
    // [1] => width
    // [2] => height
    // [3] => boolean: true if $url is a resized image, false if it is the original or if no image is available.
    ?>
    <?php endif; ?>

  4. @kisabelle kisabelle revised this gist Mar 16, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion acf.php
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@
    <?php if(get_field('logo')): ?>
    <?php
    $attachment_id = get_field('logo');
    $image_attributes = wp_get_attachment_image_src( $attachment_id );
    $image_attributes = wp_get_attachment_image_src( $attachment_id );
    // [0] => url
    // [1] => width
    // [2] => height
  5. @kisabelle kisabelle revised this gist Mar 16, 2015. No changes.
  6. @kisabelle kisabelle revised this gist Mar 16, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions acf.php
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,9 @@

    <?php echo wp_get_attachment_image( $attachment_id, $size, false, array( 'class' => 'my-class' ) ); ?>


    /* Get Image Attributes */

    <?php if(get_field('logo')): ?>
    <?php
    $attachment_id = get_field('logo');
  7. @kisabelle kisabelle revised this gist Mar 16, 2015. 1 changed file with 10 additions and 1 deletion.
    11 changes: 10 additions & 1 deletion acf.php
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,16 @@

    <?php echo wp_get_attachment_image( $attachment_id, $size, false, array( 'class' => 'my-class' ) ); ?>


    <?php if(get_field('logo')): ?>
    <?php
    $attachment_id = get_field('logo');
    $image_attributes = wp_get_attachment_image_src( $attachment_id );
    // [0] => url
    // [1] => width
    // [2] => height
    // [3] => boolean: true if $url is a resized image, false if it is the original or if no image is available.
    ?>
    <?php endif; ?>


    /*----------------------------------------------*/
  8. @kisabelle kisabelle revised this gist Mar 16, 2015. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions acf.php
    Original file line number Diff line number Diff line change
    @@ -133,9 +133,15 @@


    <?php
    /*----------------------------------------------*/
    /* User Fields
    /*----------------------------------------------*/

    // The $post_id needed is a string containing “user” + the user ID in this format: “user_$UserID”

    $variable = get_field('field_name', 'user_2');

    // do something with $variable



  9. @kisabelle kisabelle revised this gist Mar 16, 2015. 1 changed file with 17 additions and 0 deletions.
    17 changes: 17 additions & 0 deletions acf.php
    Original file line number Diff line number Diff line change
    @@ -121,5 +121,22 @@
    // no layouts found

    endif;




    /*----------------------------------------------*/
    /* Page Link
    /*----------------------------------------------*/?>

    <a href="<?php the_field('page_link'); ?>">Read this!</a>


    <?php






    ?>
  10. @kisabelle kisabelle revised this gist Jun 26, 2014. 1 changed file with 34 additions and 1 deletion.
    35 changes: 34 additions & 1 deletion acf.php
    Original file line number Diff line number Diff line change
    @@ -89,4 +89,37 @@
    'compare' => 'LIKE'
    )
    )
    ));
    ));


    /*----------------------------------------------*/
    /* Flexible Content Field
    /*----------------------------------------------*/

    <?php

    // check if the flexible content field has rows of data
    if( have_rows('flexible_content_field_name') ):

    // loop through the rows of data
    while ( have_rows('flexible_content_field_name') ) : the_row();

    if( get_row_layout() == 'paragraph' ):

    the_sub_field('text');

    elseif( get_row_layout() == 'download' ):

    $file = get_sub_field('file');

    endif;

    endwhile;

    else :

    // no layouts found

    endif;

    ?>
  11. @kisabelle kisabelle revised this gist Apr 30, 2014. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions acf.php
    Original file line number Diff line number Diff line change
    @@ -75,8 +75,6 @@
    //...
    }



    /*
    * Query posts for a checkbox value.
    * This method uses the meta_query LIKE to match the string "red" to the database value a:2:{i:0;s:3:"red";i:1;s:4:"blue";} (serialized array)
  12. @kisabelle kisabelle revised this gist Apr 30, 2014. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions acf.php
    Original file line number Diff line number Diff line change
    @@ -65,6 +65,18 @@
    /* Checkbox Field
    /*----------------------------------------------*/


    /*
    * Conditional statement (Checkbox rvalue is an array)
    */

    if( in_array( 'red', get_field('field_name') ) )
    {
    //...
    }



    /*
    * Query posts for a checkbox value.
    * This method uses the meta_query LIKE to match the string "red" to the database value a:2:{i:0;s:3:"red";i:1;s:4:"blue";} (serialized array)
  13. @kisabelle kisabelle revised this gist Apr 30, 2014. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions acf.php
    Original file line number Diff line number Diff line change
    @@ -65,6 +65,12 @@
    /* Checkbox Field
    /*----------------------------------------------*/

    /*
    * Query posts for a checkbox value.
    * This method uses the meta_query LIKE to match the string "red" to the database value a:2:{i:0;s:3:"red";i:1;s:4:"blue";} (serialized array)
    * The above value suggests that the user selected "red" and "blue" from the checkbox choices
    */

    $posts = get_posts(array(
    'meta_query' => array(
    array(
  14. @kisabelle kisabelle revised this gist Apr 30, 2014. 1 changed file with 26 additions and 3 deletions.
    29 changes: 26 additions & 3 deletions acf.php
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    /* Image Field */
    /*----------------------------------------------*/
    /* Image Field
    /*----------------------------------------------*/

    /* Return value: Attachment ID */

    @@ -15,7 +17,11 @@
    <?php echo wp_get_attachment_image( $attachment_id, $size, false, array( 'class' => 'my-class' ) ); ?>


    /* Repeater Field */


    /*----------------------------------------------*/
    /* Repeater Field
    /*----------------------------------------------*/

    <?php

    @@ -50,4 +56,21 @@

    <?php else : ?>

    <?php endif; ?>
    <?php endif; ?>




    /*----------------------------------------------*/
    /* Checkbox Field
    /*----------------------------------------------*/

    $posts = get_posts(array(
    'meta_query' => array(
    array(
    'key' => 'field_name', // name of custom field
    'value' => '"red"', // matches exaclty "red", not just red. This prevents a match for "acquired"
    'compare' => 'LIKE'
    )
    )
    ));
  15. @kisabelle kisabelle revised this gist Feb 18, 2014. 1 changed file with 15 additions and 1 deletion.
    16 changes: 15 additions & 1 deletion acf.php
    Original file line number Diff line number Diff line change
    @@ -36,4 +36,18 @@

    endif;

    ?>
    ?>

    /* Repeater Field Alternate Syntax/Markup */

    <?php if( have_rows('repeater_field_name') ): ?>

    <?php while ( have_rows('repeater_field_name') ) : the_row(); ?>

    <?php the_sub_field('sub_field_name'); ?>

    <?php endwhile; ?>

    <?php else : ?>

    <?php endif; ?>
  16. @kisabelle kisabelle revised this gist Feb 13, 2014. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions acf.php
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,10 @@
    ?>
    <?php endif; ?>

    /* Add A Class to the Img tag */

    <?php echo wp_get_attachment_image( $attachment_id, $size, false, array( 'class' => 'my-class' ) ); ?>


    /* Repeater Field */

  17. @kisabelle kisabelle revised this gist Jan 22, 2014. 1 changed file with 25 additions and 1 deletion.
    26 changes: 25 additions & 1 deletion acf.php
    Original file line number Diff line number Diff line change
    @@ -8,4 +8,28 @@
    $size = "vendor-logo"; // (thumbnail, medium, large, full or custom size)
    echo wp_get_attachment_image( $attachment_id, $size );
    ?>
    <?php endif; ?>
    <?php endif; ?>


    /* Repeater Field */

    <?php

    // check if the repeater field has rows of data
    if( have_rows('repeater_field_name') ):

    // loop through the rows of data
    while ( have_rows('repeater_field_name') ) : the_row();

    // display a sub field value
    the_sub_field('sub_field_name');

    endwhile;

    else :

    // no rows found

    endif;

    ?>
  18. @kisabelle kisabelle created this gist Jan 16, 2014.
    11 changes: 11 additions & 0 deletions acf.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    /* Image Field */

    /* Return value: Attachment ID */

    <?php if(get_field('logo')): ?>
    <?php
    $attachment_id = get_field('logo');
    $size = "vendor-logo"; // (thumbnail, medium, large, full or custom size)
    echo wp_get_attachment_image( $attachment_id, $size );
    ?>
    <?php endif; ?>