Hoi John
Thank you, that helped me alot and I have now managed it.
My biggest mistake was, that I was not saving as draft but as pending.
Thank you very much
Roman
Hi John
Thank you for helping me out.
To make it more precise:
I have a frontend form where anyone can add a post to a cpt.
This post is saved as draft until the site-owner is publishing the post.
After filling the form on frontend, a mail should go to the client with a thank you message that his post will be published if everyting is ok.
Thats where I have used acf/save_post.
This is my Code
add_action('acf/save_post' , 'my_save_post', 20);
function my_save_post($post_id) {
// If not CPT, exit
if( get_post_type($post_id) !== 'inserate' ) {
return;
}
add_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
// get custom fields (field group exists for content_form)
$name = get_field('name', $post_id);
$email = get_field('email', $post_id);
$to = $email;
$headers = 'From: ' . $name . ' <' . $email . '>' . "\r\n";
$subject = 'Thank you';
$message = 'Thank you for submitting a post';
wp_mail($to, $subject, $message, $headers );
remove_filter( 'wp_mail_content_type', 'wpdocs_set_html_mail_content_type' );
}
Now my question is, to just send this mail after submitting the form, but not after publishing. At the moment the action is fired multiple times and I need a check for the post status or something else.
Roman
Hi John
Would you please explain how we can check the post status?
I have exactly the same issue.
After a form is submitted a new CPT-entry is made as draft.
The email goes out to the client who has filled that form.
After reviewing and publishing the post, the mail goes out for a second time.
On submit I have a mail like “thank you, we will check and publish”.
After publishing it would be great to have another mail like “your post is published now” … or at least not the same mail again.
Thank you
I may have a solution by adding duplicates for all my products. That seems to be an easy way to resolve that.
Thank you very much for your help!
Hi James
Thak you!
This is my JSON-File.
“field_56c19dd4c3e9c” is the repeater I want the alphabetical list of.
{
"key": "group_56cd64f9096fa",
"title": "Veranstaltungen",
"fields": [
{
"key": "field_54c7409720a78",
"label": "Date",
"name": "date",
"type": "date_picker",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"display_format": "l, d. F Y",
"return_format": "Ymd",
"first_day": 1
},
{
"key": "field_54c7412220a79",
"label": "Time",
"name": "time",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": "",
"readonly": 0,
"disabled": 0
},
{
"key": "field_54c7a407e1264",
"label": "Event-Type",
"name": "type",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": "",
"readonly": 0,
"disabled": 0
},
{
"key": "field_54c7a45be1265",
"label": "Entry fee",
"name": "entry",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": "",
"readonly": 0,
"disabled": 0
},
{
"key": "field_54d9d07b10c0a",
"label": "Supporting Act",
"name": "support",
"type": "text",
"instructions": "Supporting-Act",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": "",
"readonly": 0,
"disabled": 0
},
{
"key": "field_54c8992084720",
"label": "Links",
"name": "links",
"type": "repeater",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"row_min": "",
"row_limit": "",
"layout": "table",
"button_label": "Add new link",
"min": 0,
"max": 0,
"collapsed": "",
"sub_fields": [
{
"key": "field_54c8992e84721",
"label": "Linkname",
"name": "linkname",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"formatting": "html",
"maxlength": "",
"readonly": 0,
"disabled": 0
},
{
"key": "field_54c8993c84722",
"label": "Linkadresse",
"name": "linkadresse",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"formatting": "html",
"maxlength": "",
"readonly": 0,
"disabled": 0
}
]
},
{
"key": "field_56c19dd4c3e9c",
"label": "Artists",
"name": "artists",
"type": "repeater",
"instructions": "This field is used for the Artist-List.",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"row_min": "",
"row_limit": "",
"layout": "table",
"button_label": "Add Artist",
"min": 0,
"max": 0,
"collapsed": "",
"sub_fields": [
{
"key": "field_56c19de1c3e9d",
"label": "Artist Name",
"name": "artistname",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"formatting": "html",
"maxlength": "",
"readonly": 0,
"disabled": 0
},
{
"key": "field_56c1abe6bf667",
"label": "Artist-Website",
"name": "artistweb",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"formatting": "html",
"maxlength": "",
"readonly": 0,
"disabled": 0
}
]
},
{
"key": "field_54e5d86e27b60",
"label": "Presales",
"name": "presales",
"type": "text",
"instructions": "Link zur Vorverkaufsseite \"http:\/\/www....\"",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"placeholder": "",
"prepend": "",
"append": "",
"maxlength": "",
"readonly": 0,
"disabled": 0
},
{
"key": "field_54c8b1bf11fde",
"label": "Image Gallery",
"name": "gallery",
"type": "repeater",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"collapsed": "",
"min": "",
"max": "",
"layout": "table",
"button_label": "Fotos hinzuf\u00fcgen",
"sub_fields": [
{
"key": "field_54c8b1dc11fdf",
"label": "Bild",
"name": "bild",
"type": "image",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"preview_size": "thumbnail",
"library": "all",
"return_format": "id",
"min_width": 0,
"min_height": 0,
"min_size": 0,
"max_width": 0,
"max_height": 0,
"max_size": 0,
"mime_types": ""
}
]
},
{
"key": "field_54cb98c819900",
"label": "R\u00e9sum\u00e9",
"name": "resume",
"type": "wysiwyg",
"instructions": "Das ist ein abschliessender Text zum Event. Dieser wird angezeigt sobald Fotos in der Fotogalerie sind.",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"tabs": "all",
"toolbar": "full",
"media_upload": 1
}
],
"location": [
[
{
"param": "post_type",
"operator": "==",
"value": "post"
}
]
],
"menu_order": 5,
"position": "normal",
"style": "seamless",
"label_placement": "top",
"instruction_placement": "label",
"hide_on_screen": "",
"active": 1,
"description": "",
"modified": 1456303465
}
Hi James
No, sorry, I don`t get it to work. I always get errors.
My repeater is: “artists”
Sub-fields: “artistname” / “artistweb”
“artistname” is always set, “artistweb” only if an artsit has a website.
I want a list sorted by “artistname”
Would be very happy if someone can help me out.
Roman
ohh, not absolutely solved, sorry.
With the code above I get the list of all sub custom field values “artistname”, but not 100% correct. They are still sorted by posts (query-type “events”) somehow.
If events have only one row it works fine
exmpl:
Event 1 – artist – Abba
Event 2 – artist – Duran Duran
Event 3 – artist – Foo Fighters
But if an events has more then one row, not the row itselves is posted alphabeticaly.
exmpl:
Event 4 – artist – Coldplay, Aerosmith, Eminem
The list looks like this:
It should look lite that, 100% alphabeticaly:
ok, now I got it.
This is my solution if someone is interested:
<?php
// filter
function my_posts_where( $where ) {
$where = str_replace("meta_key = 'artists_%", "meta_key LIKE 'artists_%", $where);
return $where;
}
add_filter('posts_where', 'my_posts_where');
// find todays date
$today = date('Ymd');
$args = array(
'posts_per_page' => '-1',
'post_type' => 'veranstaltungen',
'orderby' => 'meta_value',
'meta_key' => 'artists_%_artistname',
'order' => 'ASC',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'datum',
'value' => $today,
'compare' => '<',
),
array(
'key' => 'artists_%_artistname',
)
)
);
query_posts( $args );
?>
Thank you for your hint. I tried alot but have no clue where it stucks. would be nice if someone can give me another hint.
My repeater-field is “artists“, in there is a sub-field called “artistname“.
My goal is a list of artistnames played in the past, sorted alphabetically (if possible without doubles, if an artist player more than once in the club).
So far it displays all artistnames, but not alphabetically.
My query so far:
<?php
// filter
function my_posts_where( $where ) {
$where = str_replace("meta_key = 'artists_%", "meta_key LIKE 'artists_%", $where);
return $where;
}
add_filter('posts_where', 'my_posts_where');
// find todays date
$today = date('Ymd');
$args = array(
'posts_per_page' => '-1',
'post_type' => 'veranstaltungen',
'orderby' => 'artist_clause',
'order' => 'ASC',
'meta_query' => array(
'relation' => 'AND',
'date_clause' => array(
'key' => 'datum',
'value' => $today,
'compare' => '<',
),
'artist_clause' => array(
'key' => 'artists_%_artistname',
)
)
);
query_posts( $args );
?>
Thank you
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.