Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update accessing values functions parameters to include container_id #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions documentation/10-containers/20-post-meta.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,22 @@ The priority within the context where the container should show (`'high'` (defau

### Accessing field values

To access field values you need to use the function `carbon_get_post_meta( $id, $name )`, where:
To access field values you need to use the function `carbon_get_post_meta( $id, $name, $container_id = '' )`, where:

| Parameter | Description |
| -------------------- | ----------------------------------------------------------------------------------- |
| `$id` | Post ID where your value was entered. |
| `$name` | The field name pattern of the field to be retrieved. |
| `$id` | Post ID where your value was entered. (required) |
| `$name` | The field name pattern of the field to be retrieved. (required) |
| `$container_id` | The container id for which to retrieve the field value. (optional) |

*Container ID is generated from the `carbon_fields_container_` prefix and sanitized version of the Container Name. For example if you define `post_meta` Container named `Post Settings` its id will be - `carbon_fields_container_post_settings`. Passing the container id is recommended if you have defined fields with same names and in different containers.*

```php
<!-- Simple field -->
<p>Article was published in: <?php echo carbon_get_post_meta( get_the_ID(), 'crb_location' ); ?></p>

<!-- Complex field -->
<?php
<?php
$slides = carbon_get_post_meta( get_the_ID(), 'crb_slides' );
if ( $slides ) {
foreach ( $slides as $slide ) {
Expand Down Expand Up @@ -65,4 +68,4 @@ function crb_after_save_event( $post_id ) {
update_post_meta( $post_id, '_crb_event_timestamp', $timestamp );
}
}
```
```
9 changes: 5 additions & 4 deletions documentation/10-containers/30-theme-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,18 @@ Container::make( 'theme_options', 'Basic Options' )

### Accessing field values

To retrieve field values from a theme options container, you need to use the function `carbon_get_theme_option( $name )`, where:
To retrieve field values from a theme options container, you need to use the function `carbon_get_theme_option( $name, $container_id = '' )`, where:

| Parameter | Description |
| -------------------- | ----------------------------------------------------------------------------------- |
| `$name` | The field name pattern of the field to be retrieved. |
| `$name` | The field name pattern of the field to be retrieved. (required) |
| `$container_id` | The container id for which to retrieve the field value. (optional) See [Post Meta Container](/containers/post-meta?id=accessing-field-values) for more info. |

```php
<p>Copyright <?php echo carbon_get_theme_option( 'crb_copyright' ); ?></p>
<p>
Office locations:
<?php
<?php
$address_lines = carbon_get_theme_option( 'crb_addresses' );
foreach ( $address_lines as $line ) {
echo $line . '<br/>';
Expand All @@ -146,4 +147,4 @@ To retrieve field values from a theme options container, you need to use the fun
<p>
```

After saving, the `carbon_fields_theme_options_container_saved` hook is called, which allows you to hook additional functionality after saving.
After saving, the `carbon_fields_theme_options_container_saved` hook is called, which allows you to hook additional functionality after saving.
11 changes: 6 additions & 5 deletions documentation/10-containers/40-term-meta.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,25 @@ Container::make( 'term_meta', 'Category Properties' )

### Accessing field values

To access field values you need to use the function `carbon_get_term_meta( $term_id, $name )`, where:
To access field values you need to use the function `carbon_get_term_meta( $term_id, $name, $container_id = '' )`, where:

| Parameter | Description |
| -------------------- | ----------------------------------------------------------------------------------- |
| `$term_id` | Term ID where your value was entered. |
| `$name` | The field name pattern of the field to be retrieved. |
| `$term_id` | Term ID where your value was entered. (required) |
| `$name` | The field name pattern of the field to be retrieved. (required) |
| `$container_id` | The container id for which to retrieve the field value. (optional) See [Post Meta Container](/containers/post-meta?id=accessing-field-values) for more info. |

```php
<!-- Simple field -->
<p>Editor of this category: <?php echo carbon_get_term_meta( $category->term_id, 'crb_editor' ); ?></p>

<!-- Complex field -->
<?php
<?php
$authors = carbon_get_term_meta( $category->term_id, 'crb_authors' );
foreach ( $authors as $author ) {
echo $author['name'];
}
?>
```

After saving, the `carbon_fields_term_meta_container_saved` hook is called, which allows you to hook additional functionality after saving. It accepts the `$term_id` parameter, which is the `term_id` of the taxonomy term that was updated.
After saving, the `carbon_fields_term_meta_container_saved` hook is called, which allows you to hook additional functionality after saving. It accepts the `$term_id` parameter, which is the `term_id` of the taxonomy term that was updated.
9 changes: 5 additions & 4 deletions documentation/10-containers/50-user-meta.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ Container::make( 'user_meta', 'Address' )

### Accessing field values

To access field values you need to use the function `carbon_get_user_meta( $user_d, $name )`, where:
To access field values you need to use the function `carbon_get_user_meta( $user_id, $name, $container_id = '' )`, where:

| Parameter | Description |
| -------------------- | ----------------------------------------------------------------------------------- |
| `$user_id` | User ID where your value was entered. |
| `$name` | The field name pattern of the field to be retrieved. |
| `$user_id` | User ID where your value was entered. (required) |
| `$name` | The field name pattern of the field to be retrieved. (required) |
| `$container_id` | The container id for which to retrieve the field value. (optional) See [Post Meta Container](/containers/post-meta?id=accessing-field-values) for more info. |

```php
<!-- Simple field -->
<p>Author address: <?php echo carbon_get_user_meta( get_the_author_meta( 'ID' ), 'crb_street' ); ?></p>

<!-- Complex field -->
<?php
<?php
$phone_numbers = carbon_get_user_meta( get_the_author_meta( 'ID' ), 'crb_phone_numbers' );
foreach ( $phone_numbers as $phone ) {
echo $phone['country_code'] . '-' . $phone['number'];
Expand Down
9 changes: 5 additions & 4 deletions documentation/10-containers/60-comment-meta.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ Container::make( 'comment_meta', 'Comment Information' )

### Accessing field values

To access field values you need to use the function `carbon_get_comment_meta( $comment_id, $name )`, where:
To access field values you need to use the function `carbon_get_comment_meta( $comment_id, $name, $container_id = '' )`, where:

| Parameter | Description |
| -------------------- | ----------------------------------------------------------------------------------- |
| `$comment_id` | Comment ID where your value was entered. |
| `$name` | The field name pattern of the field to be retrieved. |
| `$comment_id` | Comment ID where your value was entered. (required) |
| `$name` | The field name pattern of the field to be retrieved. (required) |
| `$container_id` | The container id for which to retrieve the field value. (optional) See [Post Meta Container](/containers/post-meta?id=accessing-field-values) for more info. |

```php
<?php $comments = get_comments( array(
Expand All @@ -40,4 +41,4 @@ foreach ( $comments as $comment ) {
}
}
?>
```
```
13 changes: 7 additions & 6 deletions documentation/10-containers/80-nav-menu-item.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ Containers are rendered in the order they are initialized.

### Accessing field values

Since each menu entry is a post from post type `"nav_menu_item"` with status `"publish"`, the values can be accessed with the function `carbon_get_nav_menu_item_meta( $nav_menu_item_ID, $name )`, where:
Since each menu entry is a post from post type `"nav_menu_item"` with status `"publish"`, the values can be accessed with the function `carbon_get_nav_menu_item_meta( $nav_menu_item_ID, $name, $container_id = '' )`, where:

| Parameter | Description |
| -------------------- | ------------------------------------------------------------- |
| `$nav_menu_item_ID` | Nav Menu Item Post ID where your value was entered. |
| `$name` | The field name pattern of the field to be retrieved. |
| Parameter | Description |
| -------------------- | -------------------------------------------------------------- |
| `$nav_menu_item_ID` | Nav Menu Item Post ID where your value was entered. (required) |
| `$name` | The field name pattern of the field to be retrieved. (required) |
| `$container_id` | The container id for which to retrieve the field value. (optional) See [Post Meta Container](/containers/post-meta?id=accessing-field-values) for more info. |

### Custom Walkers or Walker Filters

Expand Down Expand Up @@ -116,4 +117,4 @@ Both of the above examples will result in:
</li>
</ul>
</div>
```
```