# View Shortcode

{% hint style="info" %}
This page contains _View_ specific shortcode arguments. You can read about general arguments, that are the same for _Views_ and _Card_ [here](https://docs.advanced-views.com/shortcode-attributes/common-arguments).
{% endhint %}

## Default shortcode

[Classic shortcode](https://docs.advanced-views.com/shortcode-attributes/common-arguments#how-to-embed-the-shortcode):

```bbcode
[avf_view name="Name of View" view-id="651d5d75bfdf2"]
```

{% hint style="info" %}
Note: Displays the _View_, chosen meta fields should be filled at the same object where the shortcode is pasted (post/page), replace view-id="**651d5d75bfdf2**" with the ID of your _View_.
{% endhint %}

[In PHP code](https://docs.advanced-views.com/shortcode-attributes/common-arguments#how-to-embed-the-shortcode):

{% code overflow="wrap" %}
```php
<?php

// a) using do_shortcode
echo do_shortcode('[avf_view name="Name of View" view-id="651d5d75bfdf2"]');

// b) using the special plugin class
use Org\Wplake\Advanced_Views\Bridge\Advanced_Views;

echo Advanced_Views::view_shortcode('651d5d75bfdf2', 'name')
    ->render();
```
{% endcode %}

By default, View shortcodes contain two arguments: "name" and "view-id". The "name" is used for clarification purposes only and doesn't play any functional role. The "view-id" argument is the most important as it allows Advanced Views to associate the shortcode with a specific View.

## Arguments

Besides the [common shortcode arguments](https://docs.advanced-views.com/shortcode-attributes/common-arguments), the _View_ shortcode has the following arguments:

### object-id

This argument allows to define a source, from which the _View_ fields will be loaded. By default, the object-id argument is skipped, and Advanced Views automatically picks up ID of the currently displayed object (current post/page/taxonomy). If you need to change the default behavior, see the details below.

#### 1. Loading fields from a specific post/CPT item

[Classic shortcode](https://docs.advanced-views.com/shortcode-attributes/common-arguments#how-to-embed-the-shortcode):

```bbcode
By ID: [avf_view name="Name of View" view-id="651d5d75bfdf2" object-id="ANOTHER_POST_ID"]
By Slug: [avf_view name="Name of View" view-id="651d5d75bfdf2" object-id="post" post-slug="my-slug"]
```

[In PHP code](https://docs.advanced-views.com/shortcode-attributes/common-arguments#how-to-embed-the-shortcode):

{% code overflow="wrap" %}
```php
<?php

// 1. using do_shortcode

// 1.1) using do_shortcode by ID
echo do_shortcode('[avf_view name="Name of View" view-id="651d5d75bfdf2" object-id="ANOTHER_POST_ID"]');

// 1.2) using do_shortcode by Slug
echo do_shortcode('[avf_view name="Name of View" view-id="651d5d75bfdf2" object-id="post" post-slug="my-slug"]');

// 2. using the special plugin class
use Org\Wplake\Advanced_Views\Bridge\Advanced_Views;

// 2.1) using the special plugin class by ID
echo Advanced_Views::view_shortcode('651d5d75bfdf2', 'name')
    ->set_object_id('ANOTHER_POST_ID')
    ->render();
    
// 2.2) using the special plugin class by Slug
echo Advanced_Views::view_shortcode('651d5d75bfdf2', 'name')
    ->set_object_id('post')
    ->set_post_slug('my-slug')
    ->render();
```
{% endcode %}

Loading by ID is the default approach. However, loading by slug is preferred if you have multiple environments (e.g., Localhost and Live) where IDs may differ, especially if synchronization is not performed regularly.

2\. Loading fields from an option page

{% hint style="info" %}
If you made your option page using the [Advanced Custom Fields options feature](https://www.advancedcustomfields.com/resources/options-page/), you should use the "options" keyword for ANY options page.

If you made your option page using the [MB Settings page feature](https://docs.metabox.io/extensions/mb-settings-page/), you should use the ID of your options page in the argument.
{% endhint %}

[Classic shortcode](https://docs.advanced-views.com/shortcode-attributes/common-arguments#how-to-embed-the-shortcode):

```bbcode
[avf_view name="Name of View" view-id="651d5d75bfdf2" object-id="options"]
```

[In PHP code](https://docs.advanced-views.com/shortcode-attributes/common-arguments#how-to-embed-the-shortcode):

{% code overflow="wrap" %}
```php
<?php

// a) using do_shortcode
echo do_shortcode('[avf_view name="Name of View" view-id="651d5d75bfdf2" object-id="ANOTHER_POST_ID"]');

// b) using the special plugin class
use Org\Wplake\Advanced_Views\Bridge\Advanced_Views;

echo Advanced_Views::view_shortcode('651d5d75bfdf2', 'name')
    ->set_object_id('options')
    ->render();
```
{% endcode %}

#### 3. Loading fields from a User profile

[Classic shortcode](https://docs.advanced-views.com/shortcode-attributes/common-arguments#how-to-embed-the-shortcode):

{% code overflow="wrap" %}
```bbcode
[avf_view name="Name of View" view-id="651d5d75bfdf2" object-id="user" user-id="YOUR_USER_ID_HERE"]
```
{% endcode %}

{% hint style="info" %}
The second argument, user-id is optional. If you skip it, Advanced Views will automatically get the id of the current user during rendering and load fields from it.&#x20;

Note:  "current user" doesn't mean the user who has made the _View_, or pasted the shortcode, but the specific user, who is visiting the page.
{% endhint %}

[In PHP code](https://docs.acfviews.com/shortcode-attributes/common-arguments#how-to-embed-the-shortcode):

{% code overflow="wrap" %}
```php
<?php

// a) using do_shortcode
echo do_shortcode('[avf_view name="Name of View" view-id="651d5d75bfdf2" object-id="user" user-id="YOUR_USER_ID_HERE"]');

// b) using the special plugin class
use Org\Wplake\Advanced_Views\Bridge\Advanced_Views;
use Org\Wplake\Advanced_Views\Bridge\Interfaces\Shortcodes\View_Shortcode_Interface;

echo Advanced_Views::view_shortcode('651d5d75bfdf2', 'name')
    ->set_object_id(View_Shortcode_Interface::OBJECT_OPTIONS)
    ->set_user_id(1) // your user id here
    ->render();
```
{% endcode %}

#### 4. Loading fields from a taxonomy term

[Classic shortcode](https://docs.advanced-views.com/shortcode-attributes/common-arguments#how-to-embed-the-shortcode):

{% code overflow="wrap" %}
```bbcode
[avf_view name="Name of View" view-id="651d5d75bfdf2" object-id="term" term-id="YOUR_TERM_ID_HERE"]
```
{% endcode %}

{% hint style="info" %}
If you paste the shortcode on the term template/page, the second argument can be omitted.
{% endhint %}

[In PHP code](../common-arguments#how-to-embed-the-shortcode):

<pre class="language-php" data-overflow="wrap"><code class="lang-php">&#x3C;?php

// a) using do_shortcode
echo do_shortcode('[avf_view name="Name of View" view-id="651d5d75bfdf2" object-id="term" term-id="YOUR_TERM_ID_HERE"]');

// b) using the special plugin class
use Org\Wplake\Advanced_Views\Bridge\Advanced_Views;
use Org\Wplake\Advanced_Views\Bridge\Interfaces\Shortcodes\View_Shortcode_Interface;

<strong>echo Advanced_Views::view_shortcode('651d5d75bfdf2', 'name')
</strong>    ->set_object_id(View_Shortcode_Interface::OBJECT_TERM)
    ->set_term_id(1) // your term id here
    ->render();
</code></pre>

#### 5. Loading fields from a comment&#x20;

[Classic shortcode](https://docs.advanced-views.com/shortcode-attributes/common-arguments#how-to-embed-the-shortcode):

{% code overflow="wrap" %}
```bbcode
[avf_view name="Name of View" view-id="651d5d75bfdf2" object-id="comment" comment-id="YOUR_COMMENT_ID_HERE"]
```
{% endcode %}

[In PHP code](https://docs.advanced-views.com/shortcode-attributes/common-arguments#how-to-embed-the-shortcode):

{% code overflow="wrap" %}
```php
<?php

// a) using do_shortcode
echo do_shortcode('[avf_view name="Name of View" view-id="651d5d75bfdf2" object-id="comment" comment-id="YOUR_COMMENT_ID_HERE"]');

// b) using the special plugin class
use Org\Wplake\Advanced_Views\Bridge\Advanced_Views;
use Org\Wplake\Advanced_Views\Bridge\Interfaces\Shortcodes\View_Shortcode_Interface;

echo Advanced_Views::view_shortcode('651d5d75bfdf2', 'name')
    ->set_object_id(View_Shortcode_Interface::OBJECT_COMMENT)
    ->set_comment_id(1) // your comment id here
    ->render();
```
{% endcode %}

#### 6. Loading fields from a menu

[Classic shortcode](https://docs.advanced-views.com/shortcode-attributes/common-arguments#how-to-embed-the-shortcode):

{% code overflow="wrap" %}
```bbcode
[avf_view name="Name of View" view-id="651d5d75bfdf2" object-id="menu" menu-slug="YOUR_MENU_SLUG_HERE"]
```
{% endcode %}

[In PHP code](https://docs.advanced-views.com/shortcode-attributes/common-arguments#how-to-embed-the-shortcode):

{% code overflow="wrap" %}
```php
<?php

// a) using do_shortcode
echo do_shortcode('[avf_views name="Name of View" view-id="651d5d75bfdf2" object-id="menu" menu-slug="YOUR_MENU_SLUG_HERE"]');

// b) using the special plugin class
use Org\Wplake\Advanced_Views\Bridge\Advanced_Views;
use Org\Wplake\Advanced_Views\Bridge\Interfaces\Shortcodes\View_Shortcode_Interface;

echo Advanced_Views::view_shortcode('651d5d75bfdf2', 'name')
    ->set_object_id(View_Shortcode_Interface::OBJECT_MENU)
    ->set_menu_slug('main-menu') // your menu slug here
    ->render();
```
{% endcode %}

#### 7. Loading fields from a menu item

In WordPress, every menu item is a Post. So you can load a _View_ from the Menu item by passing its ID into the object-id argument, like in the first "[Loading fields from a specific post/CPT item](#id-1.-loading-fields-from-a-specific-post-cpt-item)" case.&#x20;

## FAQs

<details>

<summary>Shortcode shows (internal use only)</summary>

In the Pro version of the plugin, use "Parent Group" if you plan to select Fields from the same Field Group. If you make use of the "Parent Group" and "Parent field" then the shortcode will show (internal use only). \
That's because its reserved for Internal Views that are used for the nested setup of the group, repeater or flexible field types.\
See the [Nested Repeater guide](../guides/display-nested-repeater-fields) here.

</details>
