Advanced Views Docs
Live PlaygroundDownload PluginGet PRO
  • 💡Help Centre
  • ⚡Getting Started
    • Introduction
      • Key Aspects
      • Creating Your First View
      • Creating Your First Card
      • Plugin Terms
      • Plugin Interface
        • Field Options
    • Installation
      • Advanced Views Lite
      • Advanced Views Pro
      • Comparison Table
      • Upgrading from Lite to Pro
    • Supported data vendors
    • Starter theme
  • 🌟Display Content
    • WordPress
      • Post
      • Taxonomy terms
      • User
      • Comments
      • Menus
    • WooCommerce Product
    • Meta fields
      • Basic fields
        • Number
      • Content fields
        • Image
        • File
        • WYSIWYG
        • oEmbed
        • Gallery
      • Choice fields
        • Select/checkbox/radio
        • True / False
      • Relationship fields
        • Link
        • Post_object
        • Page Link
        • Relationship
        • Taxonomy
        • User
      • Advanced fields
        • Google Map
        • Google Map Multiple Markers
        • ACF OpenStreetMap Field
        • Date/time picker
      • Layout fields
        • Group (Pro)
        • Repeater (Pro)
        • Flexible (Pro)
    • Object fields
    • Custom Data (Pro)
    • Custom Gutenberg Blocks (Pro)
    • Mount Points (Pro)
    • Front-end assets management (Pro)
  • 🦸‍♂️Query Content
    • Basic Filters
    • Meta Filters (Pro)
      • Current Post
      • Comparison
      • Dynamic Injection
    • Taxonomy Filters (Pro)
    • Pagination (Pro)
    • Custom Data (Pro)
  • 🏆Shortcode Attributes
    • Common Arguments
    • View Shortcode
    • Card Shortcode
  • 🧙‍♂️Templates
    • Customizing the Template
    • Template engines
      • Twig
      • Blade
    • CSS & JS
      • BEM Methodology
      • WordPress Interactivity API
    • File system storage
    • Pre-built components
    • Reusable components library (Pro)
    • Live reload
    • Multilingual
    • Custom Ajax & Rest API (Pro)
  • ☕Guides
    • Display Custom Post Type (CPT) on another post
    • Display Employees (CPT) of a Company (CPT)
    • Display Nested Repeater Fields
    • Map Marker from ACF Image
    • Display all CPT items on a single map
  • 🛠️Tools
    • Export/Import
    • Demo Import
    • Settings
    • Preview
  • 🏹Troubleshooting
    • Compatibility
    • Report a bug
    • Payment Issues
    • Lite Support (Forum)
    • Pro Support
  • ⚙️Customization
    • Filters and Hooks
      • View
      • Card
    • Suggest a feature
    • Performance
Powered by GitBook
On this page
  • About the shortcodes
  • How to embed the shortcode
  • In non-PHP environments
  • In PHP code
  • Common arguments
  • class
  • user-with-roles
  • user-without-roles
  • custom-arguments

Was this helpful?

  1. Shortcode Attributes

Common Arguments

PreviousCustom Data (Pro)NextView Shortcode

Last updated 1 month ago

Was this helpful?

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.

Views and Cards have their own shortcodes. See the examples below.

[avf_view name="Name of View" view-id="651d5d75bfdf2"]
[avf_card name="Name of Card" card-id="9i4d5d75bflo3"]

By default, View and Card shortcodes contain two arguments: "name" and "id" (view or card). 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 View or Card.

Using extra arguments, you can further configure the behaviour of View or Card instances. You can find the View shortcode arguments on and the Card shortcode arguments . 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_view name="Name of View" view-id="651d5d75bfdf2"], in places like Gutenberg or the Classic Editor, sidebars, and other locations.

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

is a built-in WordPress function that renders shortcodes within PHP code. You can use it like this:

<?php
// .. some code
echo do_shortcode('[avf_view name="Name of View" view-id="651d5d75bfdf2"]');

2. Using Advanced Views class

The Advanced Views Framework offers a dedicated class for rendering Views and Cards. This class employs the same argument names and values as the standard shortcode but converts them into methods.

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.

<?php

use Org\Wplake\Advanced_Views\Bridge\Advanced_Views;

echo Advanced_Views::view_shortcode('651d5d75bfdf2','View name')->render();
echo Advanced_Views::card_shortcode('9i4d5d75bflo3', 'Card 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 View or Card 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

use Org\Wplake\Advanced_Views\Bridge\Advanced_Views;

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

Common arguments

class

This argument allows you to add class to your View or Card main wrapper dynamically.

In most cases, you should add all the classes directly to your View or Card, but in some cases you will need to assign this class dynamically. For example, inside your Card, you may want to add some specific class to your View, that specific to this Card only.

a) Classic shortcode

[avf_view name="Name of View" view-id="651d5d75bfdf2" class="YOUR_CLASS_HERE"]
[avf_card name="Name of Card" card-id="651d5d747423a" class="YOUR_CLASS_HERE"]

b) In PHP

<?php

// a) using do_shortcode
echo do_shortcode('[avf_view name="Name of View" view-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', 'View name')
    ->set_class('YOUR_CLASS_HERE')
    ->render();

user-with-roles

user-without-roles

Both "user-with-roles" and "user-without-roles" arguments allow you restricting access to the specific View or Card.

"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 View in a View along with our Twig features (Pro) to check user roles.

a) Classic shortcode

[avf_view name="Name of View" view-id="651d5d75bfdf2" user-with-roles="ROLE1,ROLE2" user-without-roles="ROLE1,ROLE2"]
[avf_card name="Name of Card" card-id="651d5d747423a" user-with-roles="ROLE1,ROLE2" 
user-without-roles="ROLE1,ROLE2"]

Note: Insert the Role names in the ‘user-with-roles’ and/or ‘user-without-roles’ argument replacing “ROLE1,ROLE2” with your user roles.

b) In PHP

<?php

// a) using do_shortcode
echo do_shortcode('[avf_view name="Name of View" view-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', 'View name')
    ->set_user_with_roles(['administrator'])
    ->render();

custom-arguments

Custom arguments are available only inside your Custom Data snippet. They're not available directly in View or Card template. If you need to pass to use them inside the template, you can transit them in the snippet.

You can create a single Card and load it from different categories on different pages by passing a custom argument: [avf_card 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.

a) Classic shortcode

[avf_view name="Name of View" view-id="651d5d75bfdf2" custom-arguments="name=value,another-name=another-value"]
[avf_card name="Name of Card" card-id="651d5d747423a" custom-arguments="name=value,another-name=another-value"]

b) In PHP

Using the AdvancedViews class, you can pass custom arguments with any type, including objects, arrays, etc.

<?php

// a) using do_shortcode
echo do_shortcode('[avf_view name="Name of View" view-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', 'View name')
    ->set_custom_arguments([
        'name' => 'value',
        'another-name' => 'another-value',
    ])->render();

In addition, unlike do_shortcode, you can pass variables with any type, including objects and arrays to the and Custom Data snippet features.

When you use or Custom Data feature, you can pass any custom arguments to your snippet using this argument.

Pro tip: In Card, you can also access these arguments in the and using the magic prefix: $custom-arguments$.my-field.

🏆
this page
here
do_shortcode
View
Card
View
Card
Meta
Taxonomy filters