ACF Relationship - Get Parent's Post Object

I've a few post that have ACF relationship field set up : - Post A - Post A1 - Post A2 - Post A3 Post A have a relationship that link to : Post A1,A2 & A3... Post A1,A2,A3 have their own post templates, But inside the post templates, can I manage to get Post A's Title? Because I don't want hardcoded Post A's title on Post A1,A2,A3's fields. I'd tried this solution, but seems can't retrieve parent A's post …
Category: Web

Error in Validate Field with ACF plugin in Wordpress

I have the following problem when I am validating a field with the Advanced Custom Fields plugin in wordpress. What happens is that the field is validated correctly but the error appears on a new page instead of going out on the same page above the field to which I am validating. The code to validate is the following: function validate_fields_contact() { add_filter('acf/validate_value/name=phone_contact', 'validate_phone_number', 10, 4); } function validate_phone_number($valid, $value, $field, $input) { if (!$valid) { return $valid; } if(!preg_match("/^\+XX(\s|\d){8,12}$/", …
Category: Web

Add php code to wp_print_scripts?

Is there a way to add inline php code to the editor using wp_print_scripts? I'm trying to find a way to display text from a php string into a value of input of a block. Here's my code: function shapeSpace_print_scripts() { ?> <?php $block_yt_url = 'test';?> <script> jQuery(document).ready(function ($) { let $yt_url = false; $(document).on( "click", '#yt_run .acf-button-group', function() { $(".editor-post-publish-button__button").hide(); $(".acf-block-body div div.acf-block-fields.acf-fields div.acf-field.acf-field-text.acf-field-6260f423f1666").css({'height':'inherit','padding':'16px 20px','overflow':'inherit'}); $(".acf-block-body div div.acf-block-fields.acf-fields div.acf-field.acf-field-text.acf-field-6260f423f1666").val(<?php echo $block_yt_url;?>); $('#yt_url .acf-input input').keyup(function(e) { if(e.keyCode == 13) { …
Category: Web

Bulk Update Custom Fields for Custom Post Types

I am using this function which works great in case anyone wants to bulk update custom fields for custom post types (just change parameters as necessary). $args=array( 'posts_per_page' => -1, 'post_type' => 'mycptype' ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); $testa = get_field('br_type'); $testb = get_field('br_category'); if ($testa === 'Apples') { update_field('br_featured', '0', get_the_ID()); } endwhile; wp_reset_postdata(); endif; How to use: Insert the code inside your functions.php and refresh …
Category: Web

How to use thumbnail size of image if I'm only using src to get image

I have a custom field for an image, and using it this way: <?php $item_img = get_sub_field('image'); ?> <img src="<?php echo $item_img ?>" /> But I want to use the thumbnail version of the image, as set to 150x150 in wordpress. How do I do that with this type of setup? Do I have to set a custom add_image_size() or does wordpress have duplicated thumbmail size images?
Category: Web

How do I link to a dynamic ACF button from a Custom Post type?

I have a custom post type archive that has articles that call some ACF content on each post. I've used WP_Query to pull these articles onto the archive page, and there's a button in each article that when clicked will open a modal window with images I've placed in an ACF repeater for the custom post. How do I call the modal window by that button without calling the other modal windows open? Here's my code for the archive page: …
Category: Web

Custom fields not showing in custom post type

I'm putting together a basic landing page http://shurity.com/, and in trying to clean up my code, I wanted to replace some static content with dynamic content for the user. The element in question is the modal that pops up when you click subscribe...my text does not show up when I attempt to include it in the loop. The following code is a template file that matches the custom post type I created for the modal, and the post type has …
Category: Web

list/consult Taxonomy only for the respective author/creator in dashbboard

I'm trying to filter so that only the creators of the respective categories can edit them. I created a cat_author meta field and associated it to the taxonomy. In this way, every taxonomy has an author. And I tended to filter with add_filter( 'pre_get_terms', 'filter_cat_by_u_id', 99, 1 ); function filter_cat_by_u_id( $query ) { if ( ! is_admin() ) { return $query; } global $pagenow; if ( 'edit-tags.php' === $pagenow ) { $meta_query = array( array( 'key' => 'cat_author', 'value' => …
Category: Web

How To Save Data From Remote APIs To ACF?

I've been attempting to ingest remote data from an api partner into Wordpress. To data I've used wpallimport plugin, but it's quite limited. How would one connect with a remote api and then save the data to a an ACF field either one time or periodically? I've test out wp_remote_get($apiUrl); and even created a POC but saving the data to the WP database has not been successful yet.
Category: Web

How to get custom fields in a post when published

add_action( 'publish_post', 'sm12_publish_post' ); add_action( 'save_post', 'sm12_publish_post', 20 ); //After save meta value function sm12_publish_post( $postid ){ /** some checks */ if( "publish" != get_post_status( $postid ) ) return; $post= get_post($postid); $sub = 'test subject'; $mgs = 'test message'; wp_mail( '[email protected]', $email, $mgs); } I need to get the custom fields to my frontend (Laravel) from Wordpress Backend. The post was successfully saved, and I was able to get the Post ID and title, but I can't fetch the values …
Category: Web

How to make a custom search template for custom taxonomy?

I have created the custom post type "truck" with custom post type ui plugin. I then created a couple of custom taxonomies "make" and "model". I am using Advanced Custom Fields in the templates to display the output the way I want it. I have everything looking and working the way I want it to.. almost. I am using the plugin search & filter to allow for filtering by custom taxonomy. So where I am getting hung up is when …
Category: Web

get all posts in custom post type by ACF field value

I have a custom post type with custom fields(advanced custom fields plugin). one of the custom fields named program_id. i can`t understand how to get all of the posts in that CPT where the ACF field value is x, and only them. i read ACF guide but i always get all of the post. $student_query_args = [ 'post_type' => 'student_list', 'post_status' => 'publish', 'posts_per_page' => 100, 'order' => 'DESC', 'meta_query' => [ 'key' => 'program_id', 'value' => 5317, ], ]; …
Category: Web

ACF to select posts not displaying on blog page

I am trying to implement a repeater / post object so I can select posts that I want to displaying on the sidebar. I am using this code: <?php while ( have_rows('top_posts_repeater')) : the_row(); // loop through the repeater fields ?> <?php // set up post object $post_object = get_sub_field('selection'); if( $post_object ) : $post = $post_object; setup_postdata($post); ?> <article class="your-post"> <?php the_title(); ?> <?php the_post_thumbnail(); ?> <?php // whatever post stuff you want goes here ?> </article> <?php wp_reset_postdata(); …
Category: Web

Having a repeating custom field in admin custom post type, what I'd go better with, for DB's sake? ACF repeater or query a different post type?

I have: A main custom post type - 'Cards' - each post showing its ACF repeater custom field - 'operations' - with the following sub-fields: 'add/remove', 'amount, 'value', 'date'. Let's say the fully operational website will have 500 Cards posts, with about 50/100 operation rows each. What would be the less stressing solution, to keep querys and Database load reasonable? Keeping my first choice and use custom fields with ACF repeater, inside the Cards posts. Creating a dedicated custom post …
Category: Web

How to inherit field value from parent post into in child / sub post

I have created a custom post type, called 'centres'. This CPT is hierarchical, ie, I can create child pages under each custom post. Centre1 Location1 Contact1 Centre 2 Location2 Contact2 I've defined a custom field called phone_number. This field is populated at the 'parent' level. Ie, Centre1, Centre2. I want to display the phone number on each child page. I don't want to have to add the phone number every time to each page, so would like to get or …
Category: Web

How to filter get_post with ACF by a checkbox field?

So, I have a custom content type called "team" where I have an ACF field attached called "external" which is a checkbox. I am currently getting all the posts by passing the following arguments array to the get_post function. $args = array( 'posts_per_page' => -1, 'offset' => 0, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_type' => 'team', 'post_status' => 'publish', ); What I'd like to do is run this in two functions checking if the field is or is not …
Category: Web

Get posts with multiple meta values

I have a ACF select field which takes multiple value. Now I want to use get_posts() to get those custom posts. My arguments look like this: $party = 'test1'; $function = 'test1, test2'; $args = array( 'numberposts' => -1, 'post_type' => 'event', 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'party', 'compare' => '=', 'value' => $party, ), array( 'key' => 'function', 'compare' => 'IN', 'value' => array($function), ) ) ); $items = get_posts($args); But this does not work! …
Category: Web

Rewrite comment form post ID on submit

I have a WordPress comment form, with a custom field (added with the Advanced Custom Field plugin) where the visitor can chose from a options (these are page IDs). When submitting the form, I want this select value to replace the comment_post_ID that by default adds the current page ID. What I'm trying to achieve is having a global comment form on just one page and then for the visitor to select a page (in our case, these are medical …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.