Advanced title and Content fields

With these options you can combine or replace more fields to the title and description field. There are two default variables:

  1. {titlefield} - this is the default title value

  2. {descriptionfield} - the default description value

..as well as a number of special variables.

Special variables

These variables are automatically set from the result fields:

  • {__id} - The post ID

  • {__content} - The post content

  • {__title} - The post title

  • {__post_type} - The post type slug

  • {__image} - Image URL parsed by Ajax Search Pro

  • {__link} - The final result link

  • {__date} - The post date

  • {__author} - Post author name

Anything besides these inside "{}" crates is treated as a custom field name or taxonomy name if prefixed with '_taxonomy_' or '__tax_' words. These fields support HTML tags as well.

For advanced title and content fields for user results, please check this documentation after uderstanding this chapter.

Custom field syntax

This will print the content of the custom field (post meta) named 'custom_field'.

{custom_field}

There are also some accepted arguments:

{custom_field maxlength=130 separator=' '}

Accepted arguments

  • maxlength (int) - Maximum overall length of the resulting field string

  • separator - (string) separator between the items when the value is an array. Default: ' '

User meta field syntax (author meta)

This prints the content of a user meta field, of the author of the current post type object. If you are looking for advanced title and content fields for user results, please check this documentation.

{__um_custom_field}

With arguments:

{__um_custom_field maxlength=130}

Accepted arguments

  • maxlength (int) - Maximum overall length of the resulting field string

Taxonomy term (category, post tag etc..) syntax

{_taxonomy_category} or{__tax_category}

This will print 5 items from the category taxonomy, separated by comma. These values are changeable via arguments, as well as other things:

{__tax_category count=5 separator=', ' orderby='name' order='ASC' exclude='1' maxlength=130}

Accepted arguments:

  • count - (int) number of terms to print, default: 5

  • separator - (string) separator between the items, default: ', '

  • orderby - (string) the ordering criteria ( 'name', 'slug', 'term_group', 'term_id', 'id', 'description', 'parent'), default: 'name'

  • order - (string) the ordering direction ('ASC', 'DESC'), default 'ASC'

  • exclude - (string) comma separated list of excluded terms from the list, default: '1' (aka. the Uncategorized category)

  • maxlength (int) - Maximum overall length of the resulting field string

Date formatting and date custom fields

For date fields such as Events calendar or other plugin date fields, the date_format argument can be used to pass the date format. The list of accepted PHP date format parameters can be found here.

Example

<p><strong>Starting at:</strong> {_EventStartDate date_format="Y M, d, D"}

..will output:

Number formatting for numeric custom fields

For numeric custom fields number formatting can be applied via declaring the type="number" argument.

{my_number_field type="number" thousand_separator=", " decimals=2 decimal_separator="."}

Accepted arguments

  • thousand_separator - (string) the thousand separator characer(s)

  • decimals - (int) number of decimal places to display

  • decimal_separator - (string) the decimal separator character(s)

Example

<p>Area: <strong>{property_area type=number thousand_separator=","} sq/ft</strong></p>

Output:

Post ID reference fields

Custom fields referencing post type object IDs can be handled with the is_post_id=1 argument. When this argument is set the plugin instead of printing the value gets the post title field and prints that.

Syntax

{my_post_id_field is_post_id=1}

Example

Printing the The Events Calendar plugin Venue and Organizer names

<p><strong>Venue: </strong>[{_EventVenueID is_post_id=1}]</p>
<p><strong>Organizer: </strong>[{_EventOrganizerID is_post_id=1}]</p>

Output:

Using Shortcodes in Advanced Title or Content Fields

Because the square brackets are used for conditional brackets, using shortcodes is possible via double square brackets.

To use a shortcode [my_shortcode] in the field, the brackets have to be doubled so it becomes [[my_shortcode]]

Shortcodes should not be used within conditional brackets. The shortcode contents are executed after the conditional brackets are evaluated, therefore they don't have any effect on the conditionals.

Using my_shortcode in a paragraph block

<p>[[my_shortcode]]</p>

Using a shortcode with an opening and closing tag

[[shortcode_with_closing_tag]]Shortcode Content[[/shortcode_with_closing_tag]]

Using nested shortcodes within a div element

<div>
[[nested_shortcodes]]
    [[single_shortcode]]
[[/nested_shortcodes]]
</div>

Using custom fields or special fieds as shortcode arguments

Custom fields, taxonomy terms or special variables can be used within the shortcode as arguments. This is useful if the Post ID or any other values should be passed to the shortcode.

For example:

[[my_shortcode id="{__id}"]]

In the example above my_shortcode is called with argument id with the value of the current post ID.

Simple usage examples

Example 1: You have a custom field called 'location', which holds the location name for each post, and you want to display it before the description, separated by comma.

The simplest solution would be:

{location}, {descriptionfield}

You can use HTML tags in this field as well, so let's display the location in bold letters:

<strong>{location}</strong>, {descriptionfield}

Example 2: You have WooCommerce installed and you want to output the title in the following format: "Product name - 10$"

In this case the _price custom field holds the price of a product. Then simply try the following input in the Advanced title field:

{titlefield} - {_price}

Note, that you don't need the currency symbol, the plugin will automatically detect and display it along with the formatted price! (only works with WooCommerce)

Equivalently, as in the previous example, displaying the price in strong letters:

{titlefield} - <strong>{_price}</strong>

Other notable WooCommerce fields:

  • _price_html- will display the original output of the price field, requested from WooCommerce, this includes the regular and sale price when available, like: 25.00$ 22.00$

  • _regular_price - the regular price

  • _sale_price - the sale price

  • _tax_price - price with added tax

  • _sku - The product SKU field

Example 3: You want to display 2 post categories before the post content, separated by space.

The category taxonomy contains the post categories, so the syntax is:

<p><strong>Categories:</strong> {_taxonomy_category count=2 separator=' '}</p>
{descriptionfield}

Resulting in:

Notice, that the taxonomy field is placed into a paragraph, so it shows up in a new line.

Conditional bracket examples

Only available since version 4.11

Conditional brackets are used to display custom fields, only if they have values, simple as that. If the fields in the conditional brackets does not have value or does not exist, then everything in the bracket is ignored.

Syntax

[text 1 {field1} text 2 {field2} ..text n {fieldN}..]

..where {field1} to {fieldN} is replaced with their values, and the text between the fields is displayed as it is. HTML is supported. If any of the fields is empty or does not exist, then nothing from the brackets is displayed. This becomes especially handy, if the custom fields are only set on some of the post type objects.

Examples

Example 1

You have WooCommerce and want to display some text and the price in the title, but some items does not have prices. Like so: Item title - Price: 10.0$

You need to use conditional brackets, as you don't want to display the '- Price' text if there is no price set:

{titlefield}[ - Price: {_price}]

This will result in:

Example 2

You have WooCommerce and want to display some text and the sale price, if not on sale, then the regular price in the title - but some items does not have prices. Like so: Item title - Now only: 9$ instead of - 10.0$

You need to use conditional brackets, as you don't want to display the '- Price' text if there is no price set:

{titlefield}[ - Now only: {_sale_price} instead of][ - {_regular_price}]

This will result in:

Example 3

This one is the exact one that's used on the property search example as seen on the demo site. We have fields re_property_type, re_price, re_bedrooms, re_bathrooms and re_area custom fields, attached to a real estate custom post type. As the fields name imply, they contain the property type, price, bedrooms and bathrooms count and the area in sq feet.

We use the following Advanced description field code to display those fields:

[<p><strong>{re_property_type}</strong></p>]
[<p>Price: {re_price}$</p>]
[<p>Rooms: {re_bedrooms}</p>]
[<p>Bathrooms: {re_bathrooms}</p>]
[<p>Area: {re_area} (sq feet)</p>]

..which displays as:

Last updated