Duplicate Post, SEO plugins and site search
5 min read
Three small integrations that make fields behave like the rest of WordPress.
Integration | Works with | Needs a setting? |
|---|---|---|
Yoast Duplicate Post, or any duplicator that calls an action | No | |
Yoast SEO, Rank Math | No | |
The built-in WordPress search | Include in site search, per group |
Duplicated posts
Field values are not post meta, so a plain "copy the post meta" duplicator leaves the copy with empty fields. The plugin copies the field rows when:
- Yoast Duplicate Post (the plugin called "Yoast Duplicate Post") is active. It is detected automatically, nothing to configure. The values follow the copy for Clone, New Draft (the hooks
dp_duplicate_post,dp_duplicate_pageandduplicate_post_post_copy) and Rewrite & Republish (duplicate_post_after_rewriting). With Rewrite & Republish the values of the copy are merged back into the original when the copy is republished. - Another duplicator calls the action
wpmcf/fields/copy_objectitself.
// After your own code created a copy of a post:
do_action( 'wpmcf/fields/copy_object', $original_id, $copy_id );What the copy does:
Detail | Behaviour |
|---|---|
What is copied | The values of every top-level field of every group that has a table, for posts. This includes inactive groups. |
The target already has values | They are overwritten (verified: a target value |
The source has no stored values | Nothing is copied; the target keeps what it has. |
Same pair twice in one request | Copied once (several hooks fire for one copy). |
Password fields | The stored (hashed) value is copied with the rest. |
Failure | Logged under |
WPML's own duplicate function is covered by the multilingual integration (Business). More about moving values (WXR export and import, duplicates): WordPress export files and duplicates.
SEO variables
Every active field group makes its fields available as variables in the title and description templates of Yoast SEO and Rank Math. No setting is needed.
Plugin | Variable | Example for group |
|---|---|---|
Yoast SEO |
|
|
Rank Math |
|
|
Two underscores separate the group key from the field key, and the group key is used in full (a group wpmcf_x gives wpmcf_wpmcf_x__field). Use them in Search appearance templates (Yoast), Titles & Meta (Rank Math) or in a single post's SEO box:
%%title%% - %%wpmcf_book_details__subtitle%% %%sep%% %%sitename%%In Yoast the variables are listed under the Advanced variables; the help text is Field label (Group label). In Rank Math the variable's name is the same text and its example is the field label.
What a variable returns:
Field | Result |
|---|---|
Text, Textarea, Email, URL | The text. |
WYSIWYG | The text without HTML tags, entities decoded ( |
Select | The label ( |
Checkbox | The labels, comma-separated ( |
Number | The number ( |
No value | An empty string (the variable disappears from the title). |
Other types use the field type's own output format (the same one wpmcf_the_field() prints) with the tags stripped; the result is always plain text. Repeaters, groups and similar containers were not tested and are best not used in titles.
Rules:
- Top-level fields with a column only. Password fields are never offered.
- Maximum 200 variables in total, so a very large setup does not flood the SEO plugins' lists; the groups are taken in order.
- On a single post or page the variable uses that post. On archives the post only counts inside the loop; outside it the variable is empty (the SEO plugin may ask for a specific post, which is used when it passes one).
- Variables are registered only while the SEO plugin is active. Inactive groups are not offered.
- A failure in a variable prints nothing and is logged under
integration.yoastorintegration.rank-math; it never breaks the page.
Site search
The WordPress search (?s=...) looks in the title, excerpt and content. Switch on Include in site search in a group (Settings, Group settings tab) and it also looks in the group's text fields.
"settings": { "searchable": true }Which fields are searched: Text, Text area, WYSIWYG editor, Email, URL and Select. A Select is searched by its stored value, not its label (searching Alpha did not find a field whose value is a; searching a did). Numbers, True / False, Checkbox, Repeater, Group, Relationship, Password and other fields are not searched.
How it behaves (verified on a front-end search):
Search | Result |
|---|---|
| Posts that have the word in the title, excerpt, content or a searchable field. |
| AND across words, like core: each word may be in a different place, but both must be found. |
| The phrase. |
| Posts with the first word and without the second, also in fields. |
Text inside a WYSIWYG field | Found, HTML tags included (the search is a |
Notes:
- It applies to front-end searches (a
WP_Querywiths, whereis_search()is true). The admin list screens' search is not changed. - It adds a condition to the clause core builds for each word. If another plugin rewrote that clause (a search-replacement plugin such as a relevance plugin), that word is left alone.
- The order of results is whatever core or your theme gives; field matches do not change relevance.
- It uses
LIKE '%word%'on the field columns, which cannot use an index. On very large tables, search can become slow; keep the number of searchable groups small. - Only posts. Users, terms and comments are not searched.
Troubleshooting
Problem | Fix |
|---|---|
The copy has empty fields | The duplicator is not Yoast Duplicate Post and does not call |
The variable shows as plain text in the title | The group is inactive, the key is wrong (two underscores between group and field), or the SEO plugin is not active. |
The variable is empty on an archive | By design: outside the loop there is no current post. |
Search does not find a value | Include in site search is off, the field type is not searchable, you searched a select label, or it is the admin search. |
Still stuck? Contact support