# Common Arguments

## About the shortcodes

Shortcodes is the native WordPress feature that allows you to call PHP functions in various places, e.g. inside the Gutenberg editor.

*Layouts* and *Post Selections* have their own shortcodes. See the examples below.

```shortcode
[avf-layout name="Name of View" id="651d5d75bfdf2"]
[avf-post-selection name="Name of Card" id="9i4d5d75bflo3"]
```

{% hint style="info" %}
By default, *Layouts* and *Post Selection* shortcodes contain two arguments: "name" and "id" (*Layout* or *Post Selection*). The "name" is used for clarification purposes only and doesn't play any functional role. The "id" argument is the most important as it allows Advanced Views to associate the shortcode with a specific *Layout* or *Post Selection*.
{% endhint %}

Using extra arguments, you can further configure the behavior of *Layout* or *Post Selection* instances. You can find the *Layout* shortcode arguments on [this page](https://docs.advanced-views.com/shortcode-attributes/view-shortcode) and the *Post Selection* shortcode arguments [here](https://docs.advanced-views.com/shortcode-attributes/card-shortcode). However, both shortcodes share a common argument that allows you to restrict content visibility. See the information below.

## How to embed the shortcode

### In non-PHP environments

WordPress shortcodes can be added as plain text in almost any location. WordPress automatically parses them during rendering, calls the related PHP functions, and replaces the shortcode with the generated output. You can paste the shortcode, such as `[avf-layout name="Name of View" id="651d5d75bfdf2"]`, in places like Gutenberg or the Classic Editor, sidebars, and other locations.

{% hint style="info" %}
If the location isn't processing the shortcode and only shows the actual shortcode, then try using the HTML or Shortcode field or element in your page builder.
{% endhint %}

### In PHP code

If you need to use a shortcode within PHP code, such as in your theme templates, there are two methods to achieve this:

#### 1. Using the native `do_shortcode` function

[do\_shortcode](https://developer.wordpress.org/reference/functions/do_shortcode/) is a built-in WordPress function that renders shortcodes within PHP code. You can use it like this:

```php
<?php
// .. some code
echo do_shortcode('[avf-layout name="Name of Layout" id="651d5d75bfdf2"]');
```

#### 2. Using Advanced Views class

Advanced Views offers a dedicated class for rendering *Layouts* and *Post Selections*. This class employs the same argument names and values as the standard shortcode but converts them into methods.&#x20;

Consequently, when you're editing PHP files in your IDE, you can leverage autocomplete suggestions to access the list of available arguments without the need to consult the documentation.

In addition, unlike `do_shortcode`, you can pass variables with any type, including objects and arrays to the [*Layout*](https://docs.advanced-views.com/display-content/custom-data-pro) and [*Post Selection*](https://docs.advanced-views.com/query-content/custom-data-pro) Custom Data snippet features.&#x20;

```php
<?php

use Org\Wplake\Advanced_Views\Bridge\Advanced_Views;

echo Advanced_Views::view_shortcode('651d5d75bfdf2','Layout name')->render();
echo Advanced_Views::card_shortcode('9i4d5d75bflo3', 'Post Selection name')->render();
```

The methods require two arguments: a unique ID and a name. The name is used for clarification purposes only, so it doesn't need to be identical to the current *Layout* or *Post Selection* name.

If you need to set up extra arguments, you can call the related methods before the render call. For example, let's consider the example with the `user-with-roles` argument described below on this page:

```php
<?php

use Org\Wplake\Advanced_Views\Bridge\Advanced_Views;

echo Advanced_Views::view_shortcode('651d5d75bfdf2', 'Layout name')
    ->set_user_with_roles(['administrator'])
    ->render();
```

## Common arguments

### class

This argument allows you to add class to your *Layout* or *Post Selection* main wrapper dynamically.&#x20;

In most cases, you should add all the classes directly to your *Layout* or *Post Selection,* but in some cases you will need to assign this class dynamically. For example, inside your *Post Selection*, you may want to add some specific class to your *Layout,* that specific to this *Post Selection* only.&#x20;

#### a) Classic shortcode

{% code overflow="wrap" %}

```shortcode
[avf-layout name="Name of Layout" id="651d5d75bfdf2" class="YOUR_CLASS_HERE"]
```

{% endcode %}

```bbcode
[avf-post-selection name="Name of Post Selection" id="651d5d747423a" class="YOUR_CLASS_HERE"]
```

#### b) In PHP

{% code overflow="wrap" %}

```php
<?php

// a) using do_shortcode
echo do_shortcode('[avf-layout name="Name of Layout" id="651d5d75bfdf2" class="YOUR_CLASS_HERE"]');

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

echo Advanced_Views::view_shortcode('651d5d75bfdf2', 'Layout name')
    ->set_class('YOUR_CLASS_HERE')
    ->render();
```

{% endcode %}

### user-with-roles

### user-without-roles

Both "user-with-roles" and "user-without-roles" arguments allow you restricting access to the specific *Layout* or *Post Selection*.&#x20;

{% hint style="info" %}
"**Restrict**" means that the shortcode won't be rendered, so if you'd like to show a restriction type message to users, then consider using a Field Layout in a *Layout* along with our Twig features (Pro) to check user role&#x73;*.*
{% endhint %}

#### a) Classic shortcode

{% code overflow="wrap" %}

```shortcode
[avf-layout name="Name of Layout" id="651d5d75bfdf2" user-with-roles="ROLE1,ROLE2" user-without-roles="ROLE1,ROLE2"]
```

{% endcode %}

```bbcode
[avf-post-selection name="Name of Post Selection" id="651d5d747423a" user-with-roles="ROLE1,ROLE2" 
user-without-roles="ROLE1,ROLE2"]
```

{% hint style="info" %}
Note: Insert the Role names in the ‘user-with-roles’ and/or ‘user-without-roles’ argument replacing “ROLE1,ROLE2” with your user roles.
{% endhint %}

#### b) In PHP

{% code overflow="wrap" %}

```php
<?php

// a) using do_shortcode
echo do_shortcode('[avf-layout name="Name of Layout" id="651d5d75bfdf2" user-with-roles="administrator"]');

// b) using the special Advanced Views class

use Org\Wplake\Advanced_Views\Bridge\Advanced_Views;

echo Advanced_Views::view_shortcode('651d5d75bfdf2', 'Layout name')
    ->set_user_with_roles(['administrator'])
    ->render();
```

{% endcode %}

### custom-arguments

When you use [*Layout*](https://docs.advanced-views.com/display-content/custom-data-pro) or [*Post Selection*](https://docs.advanced-views.com/query-content/custom-data-pro) Custom Data featur&#x65;*,* you can pass any custom arguments to your snippet using this argument.

{% hint style="warning" %}
Custom arguments are available only inside your Custom Data snippet. They're not available directly in *Layout* or *Post Selection* template. If you need to pass to use them inside the template, you can transit them in the snippet.  &#x20;
{% endhint %}

{% hint style="info" %}
Pro tip: In *Post Selection*, you can also access these arguments in the [Meta](/advanced-views/query-content/meta-filters-pro.md) and [Taxonomy filters](/advanced-views/query-content/taxonomy-filters.md) using the magic prefix: `$custom-arguments$.my-field`**.**

You can create a single *Post Selection* and load it from different categories on different pages by passing a custom argument: `[avf-post-selection custom-arguments="genre=my-genre-slug"]`.

**Note:** Use this method only for manually defined cases. If you need to load from the current page metadata, use the separate `$meta$` magic value.
{% endhint %}

#### a) Classic shortcode

{% code overflow="wrap" %}

```shortcode
[avf-layout name="Name of Layout" id="651d5d75bfdf2" custom-arguments="name=value,another-name=another-value"]
```

{% endcode %}

{% code overflow="wrap" %}

```bbcode
[avf-post-selection name="Name of Post Selection" id="651d5d747423a" custom-arguments="name=value,another-name=another-value"]
```

{% endcode %}

#### b) In PHP

{% hint style="info" %}
Using the Advanced Views class, you can pass custom arguments with any type, including objects, arrays, etc. &#x20;
{% endhint %}

{% code overflow="wrap" %}

```php
<?php

// a) using do_shortcode
echo do_shortcode('[avf-layout name="Name of Layout" id="651d5d75bfdf2" custom-arguments="name=value,another-name=another-value"]');

// b) using the special Advanced Views class

use Org\Wplake\Advanced_Views\Bridge\Advanced_Views;

echo Advanced_Views::view_shortcode('651d5d75bfdf2', 'Layout name')
    ->set_custom_arguments([
        'name' => 'value',
        'another-name' => 'another-value',
    ])->render();
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wplake.gitbook.io/advanced-views/shortcode-attributes/common-arguments.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
