WordPress Core Package enables you to utilize core WordPress features, like accessing post based data, accessing custom database tables and to use various WordPress functions.
Functions
These are the functions you can use in Expression Language when you enable the WordPress Core Package.
Content Retrieval:
-
get_the_excerpt($post)
: Fetches the excerpt of a post. -
get_the_post_thumbnail_url($post, $size)
: Retrieves the URL for the post’s featured image. -
get_the_title($post)
: Retrieves the title of a post. -
get_the_content($more_link_text, $strip_teaser, $post)
: Retrieves the content of a post. -
get_the_author()
: Retrieves the author of the current post. -
has_post_thumbnail($post)
: Determines whether a post has a featured image. -
get_post($post_id, $output, $filter)
: Retrieves post data by post ID. -
get_permalink($post, $leavename)
: Retrieves the permalink for a post. -
get_template_directory_uri()
: Retrieves the URI of the current theme’s directory. -
get_post_type($post)
: Retrieves the post type of a post. -
get_queried_object()
: Retrieves the currently queried object. -
get_term_children($term_id, $taxonomy)
: Retrieves the children of a term. -
get_page_by_path($page_path, $output, $post_type)
: Retrieves a page object by its path. -
wp_set_object_terms($object_id, $terms, $taxonomy, $append)
: Relates an object (like a post) to a term and taxonomy type. -
get_term_by($field, $value, $taxonomy, $output, $filter)
: Retrieves the term based on its field and taxonomy. -
wp_insert_term($term, $taxonomy, $args)
: Inserts a new term into the database. -
sanitize_title($title, $fallback_title, $context)
: Sanitizes a string into a slug, which is safe to use in URLs.
Meta Data:
-
get_post_meta($post_id, $key, $single)
: Retrieves metadata for a post. -
wp_get_attachment_metadata($attachment_id, $unfiltered)
: Retrieves metadata about an attachment. -
wp_get_attachment_url($attachment_id)
: Retrieves the URL of an attachment. -
wp_get_attachment_image_url($attachment_id, $size, $icon)
: Retrieves the URL of an attachment’s image. -
get_user_meta($user_id, $key, $single)
: Retrieves metadata for a user.
Options Management:
-
get_option($name, $default)
: Retrieves an option value. -
update_option($option, $value, $autoload)
: Updates the value of an option. -
delete_option($option)
: Deletes an option. -
get_site_transient($transient)
: Retrieves a site transient value. -
delete_site_transient($transient)
: Deletes a site transient. -
set_transient($transient, $value, $expiration)
: Sets a site transient value.
User and Authentication:
-
get_current_user_id()
: Retrieves the ID of the current user. -
current_user_can($capability, $args)
: Determines whether the current user has a specific capability. -
wp_hash($data, $scheme)
: Hashes data. -
wp_salt($scheme)
: Retrieves a salt value. -
wp_generate_password($length, $special_chars, $extra_special_chars)
: Generates a random password. -
wp_get_current_user()
: Retrieves the current user object. -
get_user_by($field, $value)
: Retrieves user data by a specific field. -
is_user_logged_in()
: Checks if the current user is logged in.
Content Manipulation:
-
wp_strip_all_tags($string, $removeBreaks)
: Strips all HTML tags from a string. -
wp_trim_words($text, $numWords, $more)
: Trims a string to a specified number of words. -
wpautop($text, $br)
: Adds necessary paragraph and line break tags to a string. -
wptexturize($text, $reset)
: Replaces certain characters with their corresponding HTML entities. -
wp_upload_dir()
: Retrieves the upload directory path and URL.
Post Management:
-
wp_insert_attachment($args, $file, $parent_post_id, $wp_error)
: Inserts an attachment into the database. -
wp_update_attachment_metadata($post_id, $data)
: Updates metadata for an attachment. -
wp_delete_attachment($post_id, $force_delete)
: Deletes an attachment. -
wp_delete_post($postid, $force)
: Deletes a post. -
wp_trash_post($postid)
: Moves a post to the trash. -
wp_insert_post($postarr, $wp_error)
: Inserts a post into the database. -
update_post_meta($post_id, $meta_key, $meta_value, $prev_value)
: Updates metadata for a post. -
wp_read_image_metadata($file)
: Reads metadata from an image file. -
get_post_title($post_id)
: Retrieves the title of a specific post. -
get_post_field($field, $post_id, $context)
: Retrieves a specific field from a post.
Email and Communication:
-
wp_mail($to, $subject, $message, $headers, $attachments)
: Sends an email.
URLs and Site Information:
-
home_url($path, $scheme)
: Retrieves the home URL of the site. -
get_site_url($blogId, $path, $scheme)
: Retrieves the site URL for a specific site. -
get_bloginfo($show, $filter)
: Retrieves information about the current site.
Hooks:
-
apply_filters($hook_name, $value, ...$args)
: Calls the functions added to a specific filter hook. -
do_action($hook_name, ...$args)
: Executes the functions hooked on a specific action.
Miscellaneous:
-
is_wp_error($thing)
: Checks if a given variable is a WordPress error. -
wp_call_user_func($callback, $args)
: This is a wrapper for thecall_user_func()
function, with the specificity that arguments are passed as an indexed array, instead of being spread. It also has the ability to include the required WordPress includes to make the function available (if they are not available by default).
Components
Init Current Auth User Element
Initiates the authentication process of a WordPress User and displays the data of the user.
When to use?
Use this component when you want to link WordPress User Accounts with an Alexa Skill.
How to use:
- Ensure that you have configured and propagated your service to Amazon Alexa with Account Linking enabled in the Account Linking Mode set to ‘Installation’.
- In the Name field, enter a variable name for the user to store the loaded user object in the context.
-
Leave the Set as Current User checked to set the current WordPress user as the User that has linked the account. Initially, no user is set in the service. Functions which leverage
wp_get_current_user()
will benefit the most from this option being enabled, which will be used in the service. - To prompt account linking directly from the element, check Prompt for linking. You can also use the Prompt Account Linking element, which is in the convo-core package, to initiate prompt account linking.
-
After the account linking process is successfully finished, you can access the WP_User object using the following examples:
${user.ID}
${user.nickname}
${user.user_email}
${user.get().get('user_email')}
${user.get().to_array()['user_email']}
${user.get().has_cap('manage_convoworks')}
For more information on the WP_User object, please refer to the Official WordPress documentation here.
WP Mail Element
When to Use
The WP Mail Element is used to send emails using the wp_mail()
function in WordPress. If the sender’s email address is not specified in the element, the email address of the WordPress admin will be used. Multiple email addresses can be used, separated by a comma.
How to Use
The WP Mail Element supports various email address formats, including:
- user@example.com
- user@example.com, anotheruser@example.com
- User <user@example.com>
- User <user@example.com>, Another User <anotheruser@example.com>
For more information about the wp_mail()
function, please visit the WordPress Developer Reference.
WP DB Element
Allows you to manipulate the WP database by inserting, deleting, selecting, etc.
When to Use
Use whenever you need data from the database that could not reasonably be obtained through WP Queries, or perhaps if you have an advanced idea for which you need the database.
How to Use:
-
First, choose an
Action
from the dropdown list.- You might notice that
Select
andQuery
both give you a custom field into which to enter a query. What’s the difference? Select
usesget_results()
, whileQuery
uses the genericquery()
method.
- You might notice that
-
If you chose
Insert
,Update
,Delete
, orReplace
, you will need to fill out key -> value pairs that correspond to the columns in the table you’re modifying. - In addition, you will be able to enter a format string. To do this, for each value, enter the corresponding format you wish to use.
-
Enter a name and pick a scope type under which to store the
last_result
. This is the result from the last query you’ve run. Make sure to store it with e.g.Set Parameter Element
if you wish to keep it later on, because subsequent queries will overwrite this result. -
If you are inserting data into the database, enter a name and pick a scope type for the
insert_id
that is automatically generated when you insert. As stated before, if you need this data, make sure to store it so it doesn’t get overwritten.
WP Insert Post Element
Inserts or updates a WordPress post.
When to Use
Use the WP Insert Post Element when you want to insert a post in WordPress from your Skill.
How to Use
- Enter a Name for your recently created post.
-
Type
false
in Fire After Hooks if you don’t want to fire the after insert hooks. - Fill out WP Post args which are described here, except tax_input and meta_input. The following params: meta_input and meta_input are handled in WP Post tax input and WP Post meta input
- If you want to update a post, add the ID to WP Post args. More info is available here
- If you want to add tax_input, fill out WP Post tax input. More info on that is here.
- If you want to add meta_input, fill out WP Post meta input.
After the element is executed, you will get either a WP_Post or WP_Error object as a result of wp_insert_post( array $postarr, bool $wp_error = false, bool $fire_after_hooks = true )
.
On Success
Elements in On Success will be executed if the post was inserted successfully.
You will get the recently created WP_Post in the form of (${status.post}
) object and be able to access its properties like this:
${status.post.ID}
${status.post.post_title}
${status.post.post_content}
- etc.
On Failure
Elements in On Failure will be executed if the post was not inserted successfully.
You will get the WP_Error in the form of (${status.wp_error}
) object and be able to access its properties like this:
${status.wp_error.errors}
${status.wp_error.error_data}
- etc.
WP Insert User Element
Inserts a WordPress user.
When to use?
Use this element when you want to insert a user in your WordPress site from an account linking option other than ‘installation’.
How to use:
- Enter a Name for your recently created user.
-
Retrieve the user name from the Init Amazon User Element like
${user.name}
. -
Retrieve the email from the Init Amazon User Element like
${user.email}
. - If you want to use a different role than what is associated with your WP Installation, check the property Use Custom Role and enter a role in the Role property.
- Or just select a role from the available WP Roles.
- If you want to add user_meta_input, fill out the WP User Meta Input field.
After the element is executed, you will get either a WP_User or WP_Error object as the result of wp_insert_user( array|object|WP_User $userdata )
.
On Success or On User Exists
Elements in On Success will be executed if the user was inserted successfully.
Elements in On User Exists will be executed if the user already exists.
You will get the recently created WP_User in the form of (${status.user}
) object and be able to access its properties like this:
${status.user.ID}
${status.user.data.user_login}
${status.user.data.user_email}
- etc.
On Failure
Elements in On Failure will be executed if the user was not inserted successfully.
You will get the WP_Error in the form of (${status.wpError}
) object and be able to access its properties like this:
${status.wpError.errors}
${status.wpError.error_data}
- etc.
WP Loop Element
Allows looping over WP Query Context single page results inside the element.
When to use?
You can use this element when you have a limited number of results and do not require pagination.
If you need full-featured pagination, please use WP Loop Page and WP Loop Post blocks.
WP Loop Page Block
WP Loop Page Block enables the pagination of WP_Query results in a convenient and straightforward manner. It comes with built-in pagination and post selection mechanisms.
When to use
Use WP Loop Page Block when you want to display a list of posts, products, or any other custom post type in a paginated manner.
How to use
To use WP Loop Page Block, drag and drop the block onto your WordPress page or post. Then, select the WP_Query to loop through, the number of items per page, and any additional parameters. You can customize the pagination labels and styling to match your site’s design.
Examples
- Displaying a paginated list of blog posts on the homepage.
- Creating a paginated product catalog page.
- Displaying a list of events in chronological order with pagination.
WP Loop Post Block
Use this component to access a selected loop post with built-in navigation features. Similar to the WP Loop Page Block, it offers automatic navigation capabilities, but for posts instead of pages.
When to Use
Use this component when you need to navigate through posts and access specific loop posts.
How to Use
Simply drag and drop the WP Loop Post Block onto your canvas and configure the settings to your liking. This component comes with built-in post navigation (Next, Previous) intents that will automatically trigger the desired operation on the WP Query Context.
Examples
Here are some examples of how to use the WP Loop Post Block:
- To display a single post, select the post ID in the component settings.
- To display multiple posts, select a category or tag in the component settings.
- Use the built-in post navigation intents to navigate through posts.
WP Media Context
Defines WP_Query which will return audio files to be streamed via audio player components.
When to use
This component is used to define the WP_Query that will return audio files to be streamed via audio player components.
How to use
All arguments are passed to the real WP_Query class except offset
which is 0 and paged
which is always set to true, meaning that there is no pagination. Setting the posts_per_page
you will set the max results in a playlist (20 by default).
You can use expressions when defining arguments. Check how to use expressions on the Convoworks documentation pages. The expressions are evaluated in the service scope, so you cannot use internal variables that are available inside container elements (e.g. Loop element).
Other parameters
All other parameters are optional and are allowed to be empty by the platforms (e.g. artwork), or the Convoworks provides required values. All parameters accept expressions that will be evaluated in the service context. Most of them are also in the post context, meaning that the “post” variable is available in the context (the real \Wp_Post object from the loop).
Default settings parameters
Default loop status
and Default shuffle status
define initial values that will be used when your user starts the player for the first time.
Media info
WP Media Context provides media info data that you can use through connected components (e.g. Media info element, Media block). In these components, you will provide a name under which this data (associative array) will be available, and here are the fields it consists of.
current
IAudioFile, current songnext
IAudioFile, next song if existscount
integer, playlist songs countlast
boolean, is the current song the lastfirst
boolean, is the current song the firstsong_no
integer, current song, starting from 1loop_status
boolean, is the loop mode enabledshuffle_status
boolean, is the shuffle enabledplaying
boolean, is the player currently playing
Mp3File (Song Descriptor Class)
These examples on how to access the various pieces of information apply to the current
and next
variables from the Media Info.
getFileUrl()
access to the file URL from current or next field in the media infogetSongTitle()
access to the song title from current or next field in the media infogetArtist()
access to the artist from current or next field in the media infogetSongImageUrl()
access to the image URL from current or next field in the media infogetSongBackgroundUrl()
access to background image URL from current or next field in the media info
WP Post Context Component
Use this component to query items from the wp_posts
table and convert their values into a catalog source for Amazon.
When to Use
Use this component when you have post values that you want to convert into an entity source. For example, if you have a custom post type that you want to use as an entity.
How to Use
- Enter the Entity name you wish to “override” with the catalog values. Make sure to create a dummy entity with the same name in the entity editor beforehand. You do not have to add any values to it since it will be replaced with the catalog.
-
Filter the posts you want by adding
Query parameters
. For instance, if you want to get all the posts of a given type, you can usepost_type: <your_post_type_here>
andpost_status: any
. -
Final value is what you will turn each post into. After the posts have been queried and found, each post will be iterated over, and you need to provide an expression that will turn each post into a SINGLE STRING VALUE. You can use WP functions such as
get_the_title()
,get_the_meta()
, and so on.
WP Query Context
This component defines WP_Query to be used as the source for other WP specific components and maintains the pagination and post selection info across the session.
When to use
Use this component when you want to use WP_Query as a source for other WP specific components and maintain pagination and post selection info across the session.
How to use
All arguments are passed to the real WP_Query class except offset
which is calculated dynamically and paged
which is always set to true.
You can use expressions when defining arguments. To learn more about expressions, check out the
Convoworks documentation.
The expressions are evaluated in the service scope, so you cannot use internal variables available inside container elements like the Loop element.
Maintaining the pagination
This component keeps track of the current page during navigation through results. If you want to rewind it to the beginning, for example if the sort order changes, provide an expression that evaluates to true to the Rewind navigation
component property. If you want to maintain pagination yourself, set the offset
parameter in args.
Page and post info
WP Query Context provides page info and post info data that you can use through connected components. In this component, you provide a name under which this data (associative array) is available, and here are the fields it consists of:
Page info fields
last
(boolean) – indicates if the current page is the last pagefirst
(boolean) – indicates if the current page is the first pagepage_no
(integer) – indicates the current page, starting from 1query
(actual WP_Query object) – provides the actual WP_Query object
Post info fields
abs_last
(boolean) – indicates if the current post is the last post in the resultsabs_first
(boolean) – indicates if the current post is the first post in the resultsabs_post_no
(integer) – indicates the position of the post in all results, starting from 1last
(boolean) – indicates if the current post is the last post on the current pagefirst
(boolean) – indicates if the current post is the first post on the current pagepost_no
(integer) – indicates the position of the post on the current page, starting from 1post
(actual WP_Post object) – provides the actual WP_Post objectmeta
(loaded meta for the current post) – an associative array in the key-value manner
WP Query Element
Gives access to the page info (and WP_Query object) defined by the WP Query Context component.
When to Use?
Use this element to quickly check if there are any results from the WP_Query object and prepare the appropriate user workflow accordingly. For example, you may define different responses or conversation steps based on whether there are no results, only one result, or multiple pages of results.
Not in the WordPress Loop
While you have access to the WP_Query object and its members, you cannot use WordPress functions without arguments as you are not in the WordPress loop. However, you can loop over the query.posts
array.
If you want to do a quick, fully functional loop over resulting posts, use the “WP Loop Element” and place it inside the “Has Results” flow.
WP Table Context
This component allows you to write a custom select query to retrieve values from the WP database and convert each item into a value for an Amazon catalog.
When to use?
You can use this component if you have specific values in the WP database that you want to use as catalog values. For example, you may want to query a quiz table to retrieve all the quiz names.
How to use?
- Enter the name of the entity you wish to “override” with the catalog values under the Entity name field. Create a dummy entity with the same name in the entity editor beforehand. You do not have to add any values to it since it will be replaced with the catalog.
-
Under the Query field, enter a
SELECT
query. Note that you can use public fields and methods from the globalwpdb
object, such aswpdb.prefix
. -
In the Final value field, provide an expression that will turn each row of the query into a SINGLE STRING VALUE. After the query has been executed and rows are found, each row will be iterated over, and you can access every row under the
row
name. For example, if you want to access the ID of each row, you can userow.ID
.
WP Update User Meta Element
Updates metadata of a WP User.
When to use?
Use this element when you want to update metadata of a user in your WordPress site.
How to use:
- Enter a Name for your recently updated user status variable.
-
Retrieve the User ID from the Init current auth user Element like
${user.ID}
, or use any other method of your choice. - Fill out the metadata of the user you want to update in the WP User meta input.
After the element is executed, you’ll either get a WP_User object or a false
boolean value as the result of get_user_by($field, $value)
.
On Success
Elements in the On Success section will be executed if the user was found and some metadata were provided.
You’ll get the recently updated WP_User object in the form of (${status.user}
), and you’ll be able to access its properties like this:
${status.user.ID}
${status.user.data.user_login}
${status.user.data.user_email}
- etc.
On Failure
Elements in the On Failure section will be executed if the user was not found.
You’ll get an error message in the form of (${status.error}
) object.
Exception
An exception will occur if no metadata was provided.