This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // NOTE: It is recommended to use pre get posts instead of query posts | |
| query_posts( array( 'post_type' => 'listing', 'listing_category' => 'the-category' ) ); | |
| if ( have_posts() ) : while ( have_posts() ) : the_post(); | |
| ?> | |
| <h3><?php the_title(); ?></h3> | |
| <?php the_content(); ?> | |
| <?php endwhile; endif; wp_reset_query(); ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Template Name: Project Listing | |
| * | |
| * Selectable from a dropdown menu on the edit page screen. | |
| */ | |
| ?> | |
| <?php get_header(); ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * WordPress Page Template: Project Listing | |
| */ | |
| ?> | |
| <?php get_header(); ?> | |
| <div id="container"> | |
| <div id="content"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // | |
| // Source: http://snippets.khromov.se/dynamically-populating-advanced-custom-fields-values/ | |
| // | |
| //Populate the Select field field_5587fccf24f38 with dynamic values | |
| add_filter('acf/load_field/key=field_5587fccf24f38', function($field) { | |
| //These can be dynamically generated using any PHP code | |
| $field['choices']['one'] = 'Choice one'; | |
| $field['choices']['two'] = 'Choice two'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| * In this example, we will load a textarea field from the options page (textarea field is called my_select_values) | |
| * and use the text on each line as a option for the select field’s choices. The select field in this example has a name of “color”. | |
| * Note: This is example 1 of 2 | |
| * | |
| * Source: http://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/ | |
| * | |
| * Add to your functions.php | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| * update a text field on the current post (using the field_name) | |
| */ | |
| $field_name = "text_field"; | |
| $value = "some new string"; | |
| update_field( $field_name, $value ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| * Example of how to change the permalink of groups. | |
| * The following code changes http://yoursite.com/groups | |
| * to http://yoursite.com/organizations. | |
| * This is done in bp_custom.php (Google for more info) | |
| */ | |
| define( 'BP_GROUPS_SLUG', 'organizations' ); | |
| ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| * Ran into a need for this when I wanted to place | |
| * an ACF form into a Shortcodes Ultimate spoiler. | |
| * Problem was that the form would render outside of the | |
| * spoiler accordion. Solution was to use PHP Output Buffering. | |
| */ | |
| $args = array( | |
| 'post_id' => 'new_post', | |
| 'post_title' => true, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| * Example of setting the value of an acf custom field on form submission. | |
| * In this example I'm saving the BuddyPress group id into field_56bd24ccc6fd3. | |
| */ | |
| //Populate the 'group' custom field (field_56bd24ccc6fd3) with dynamic values | |
| add_filter('acf/load_field/key=field_56bd24ccc6fd3', | |
| function($field) { | |
| global $bp; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| * Example of hooking into the Advanced Custom Field save process | |
| * to add a category to the taxonomy and attach it to the post. | |
| * This particular example retrieves the value from a custom field | |
| * named 'group_slug' and uses it as a category for the post. | |
| */ | |
| add_filter('acf/save_post', | |
| // Using a closure here but could be a separate function | |
| function($post_id) { |
OlderNewer