LOL @ smitxv : did you actually bother to read the topic ? There are 2 custom solutions in this topic and 1 native…
How can this be done by code (php) ?
I just found out the key is the post_name.
I’ve done some more testing… It looks like the error is showing properly when a $_GET value is NOT used…
Does anyone know if $_GET is messing the error up ?
Thanks for confirming the “no issue”…
Does anyone know if my solution can cause any issues ?
If you happen to read this, do you know @hube2 ?
I finally have the solution (which works for me, but I think most people can use this)… and it was so easy (in hindsight).
The only thing you need to do is remove the class order from the field.
Since I add an extra class to the repeaters I don’t want users to move, it was fairly simple to limit it to these repeaters.
jQuery(document).ready(function() {
jQuery(".disable-sorting table.acf-table td.order").removeClass("order");
});
If you want it done on all your repeaters, just remove the class .disable-sorting
.
Hmm… i cheered too soon… local it works without a hitch…
On production I still get the ‘grey error’, so back to zero 🙂
I was just able to finish the function how I expect it to work…
I think the issue was where I use $_GET[‘id’] I should have used $_POST[‘_acf_post_id’] because with $_POST it works as expected.
This is the full working result:
function pg_check_title( $valid, $value, $field, $input ) {
if ( ! $valid ) {
return $valid;
}
$post_name = sanitize_title( pg_replace_special_characters( $value ) );
if ( true == pg_slug_exists( $post_name, DpgPostTypes::LONGREAD, $_POST[ '_acf_post_id' ] ) ) {
$valid = __( 'This title already exists for a longread.', 'dpg' );
} elseif ( true == pg_slug_exists( $post_name, DpgPostTypes::TEMPLATE, $_POST[ '_acf_post_id' ] ) ) {
$valid = __( 'This title already exists for a template.', 'dpg' );
}
return $valid;
}
add_filter( 'acf/validate_value/key=field_5ae091e84cb7b', 'pg_check_title', 10, 4 );
function pg_slug_exists( $post_name, $post_type, $post_id ) {
global $wpdb;
$exclude = false;
if ( false != $post_id ) {
$exclude = " AND ID != '" . $post_id . "'";
}
if ( $wpdb->get_row( "SELECT post_name, ID FROM wp_posts WHERE post_name = '" . $post_name . "' AND post_type = '" . $post_type . "'" . $exclude . "", 'ARRAY_A' ) ) {
return true;
} else {
return false;
}
}
I also tried this:
function pg_slug_exists( $post_name, $post_type ) {
global $wpdb;
$exclude = false;
if ( isset( $_GET ) && isset( $_GET[ 'id' ] ) ) {
$exclude = " AND ID != '".$_GET[ 'id' ]."'";
}
if( $wpdb->get_row("SELECT post_name FROM wp_posts WHERE post_name = '" . $post_name . "' AND post_type = '" . $post_type . "'".$exclude."", 'ARRAY_A' ) ) {
return true;
} else {
return false;
}
}
but no luck
The option John linked to also hides the cogwheel. Isn’t that what you want ?
I think I have it working now.
If I start a new branch, I first branch from master.
Delete all groups.
Commit it.
Then delete the branch.
Then re-branch from master.
Sync all groups.
Do my stuff.
Apart from whether it’s going to happen or not…
Do you agree this would be solved probably if all (field) data would come from the json file ?
I can see the logic behind this, but I think this is ‘too much’ for me.
Do you know if what I describe, can be realised ? Basically read from json only instead of from DB, because I think that would ‘solve’ the issue.
Do you agree ?
I forgot the option kses in the form arguments, which stops sanitising on every field, but I want it only for specific fields, so it’s not ideal.
I am abandoning adding scripts on the front-end now because it is unsafe and we already noticed the disadvantages of it.
After I posted my question, I did 🙂 Well, James form ACF support gave it to me.
Set kses to false in the form arguments, see https://www.advancedcustomfields.com/resources/acf_form/#parameters.
This won’t do for me because I want one field specific, not all of them, so I’m gonna solve it differently, but you might be helped with it.
Ever found a way on how to do it on the front-end ?
Experiencing same issue.
start by dumping the value $rows before the foreach to see what it holds.
if the output is as expected, then dump $key and $row within the foreach.
I think there is either an error in $rows or $key.
@mtv.jcil did you succeed ?
I’m not very skilled in JS, so I tried several solutions, but I can’t get it to work anymore…
If anyone knows howto, please post it. Really need this.
Thanks. Good to know. Will check.
Thanks I will look into it….
Has someone else experienced their code not working anymore ??
This is the part which is not working anymore (for me):
$.extend(acf.fields.repeater, {
_mouseenter: function (e) {
if ($(this.$tbody.closest('.acf-field-repeater')).hasClass('disable-sorting')) {
console.log('HIT');
return false;
}
}
});
Yes.
You can do this by creating a repeater field, for the tabs.
Within that repeater you add:
– a tab title (field type: text)
– another repeater (field type: post object) where you can select a portfolio item
How to create tabs: https://www.w3schools.com/howto/howto_js_tabs.asp
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.