Support

Account

Forum Replies Created

  • So how would I use /query as you mention? In other words do I just change the top part of the code and that is it?

    Like this to add the sorting ASC?

    add_filter('acf/fields/relationship/query/name=jam_related_home_listing', 'my_acf_fields_relationship_query', 10, 5);
    function my_acf_fields_relationship_query( $text, $post, $field, $post_id ) {
    
      $community = get_field ('community', $post->ID);
      $sqft = get_field('sq_ft', $post->ID);
      $mls = get_field('mls', $post->ID);
      $price = get_field('price',$post->ID);
      $lot = get_field('lot', $post->ID);
    	
        if ($post->post_type == 'home_listings') {
    return "wp_posts.menu_order ASC";
    	} 	
            $text .= ' •  ' . $community->post_title .  ' •  Lot:  ' . $lot . '  •  SqFt:  ' . $sqft . ' •  MLS: ' . $mls . ' •  Price:  ' . $price . '';
        }
        return $text;
    }
  • QUICK QUESTION….(hopefully)

    How would I add the following orderby ASC to the post Object Filter function I shared above in this thread? I’m just learning PHP so it would be really helpful if you could share how I’d integrate this so that the additional data I’m showing in the backend in the Post Object sorts the list alphabetically starting A-Z:

    I’ve used this line in a WP_Query for a different code block but I’m unsure how to implement into the post object relationship filter you helped me create.

    'orderby'=> 'title', 'order' => 'ASC'

    WOULD IT LOOK LIKE THIS »

    <?php
    	add_filter('acf/fields/relationship/result/name=jam_related_home_listing', 'my_acf_fields_relationship_result', 'posts_orderby', 'orderby_pages_callback', 10, 5);
    function my_acf_fields_relationship_result( $text, $post, $field, $post_id ) {
    
      $community = get_field ('community', $post->ID);
      $sqft = get_field('sq_ft', $post->ID);
      $mls = get_field('mls', $post->ID);
      $price = get_field('price',$post->ID);
      $lot = get_field('lot', $post->ID);
    	
        if ($post->post_type == 'home_listings') {
    		
            $text .= ' •  ' . $community->post_title .  ' •  Lot:  ' . $lot . '  •  SqFt:  ' . $sqft . ' •  MLS: ' . $mls . ' •  Price:  ' . $price . '';
        }
    	
    // The posts_orderby filter
    function orderby_pages_callback($orderby_statement, $wp_query) {
    	# Verify correct post type, or any other query variable
    	if ($wp_query->get("home_listings") === "post") {
    		# In this trivial example add a reverse menu order sort
    		return "wp_posts.menu_order ASC";
    	} else {
    		# Use provided statement instead 
    		return $orderby_statement;
    	}
    }
        return $text;
    }
    
    	
    ?>
  • I see this is related to my current problem….

    How would I add orderby ASC to this block of code?

    add_filter('acf/fields/relationship/result/name=jam_related_home_listing', 'my_acf_fields_relationship_result', 10, 5);
    function my_acf_fields_relationship_result( $text, $post, $field, $post_id ) {
    
      $community = get_field ('community', $post->ID);
      $sqft = get_field('sq_ft', $post->ID);
      $mls = get_field('mls', $post->ID);
      $price = get_field('price',$post->ID);
      $lot = get_field('lot', $post->ID);
    	
        if ($post->post_type == 'home_listings') {
    		
            $text .= ' •  ' . $community->post_title .  ' •  Lot:  ' . $lot . '  •  SqFt:  ' . $sqft . ' •  MLS: ' . $mls . ' •  Price:  ' . $price . '';
        }
        return $text;
    }

    I DID FIND THE FOLLOWING ON THE CODEX AT WORDPRESS but I’m not sure which part to include in my above filter and where. https://developer.wordpress.org/reference/hooks/posts_orderby/

    // Add the callback to the posts_orderby filter
    add_filter('posts_orderby', 'orderby_pages_callback', 10, 2);
    
    // The posts_orderby filter
    function orderby_pages_callback($orderby_statement, $wp_query) {
    	# Verify correct post type, or any other query variable
    	if ($wp_query->get("post_type") === "page") {
    		# In this trivial example add a reverse menu order sort
    		return "wp_posts.menu_order DESC";
    	} else {
    		# Use provided statement instead 
    		return $orderby_statement;
    	}
    }

    I’m assuming I’d use this part:

    return "wp_posts.menu_order DESC";
    	} else {
    		# Use provided statement instead 
    		return $orderby_statement;
    	}

    LIKE THIS:

    add_filter('acf/fields/relationship/result/name=jam_related_home_listing', 'my_acf_fields_relationship_result', 10, 5);
    function my_acf_fields_relationship_result( $text, $post, $field, $post_id ) {
    
      $community = get_field ('community', $post->ID);
      $sqft = get_field('sq_ft', $post->ID);
      $mls = get_field('mls', $post->ID);
      $price = get_field('price',$post->ID);
      $lot = get_field('lot', $post->ID);
    	
        if ($post->post_type == 'home_listings') {
    return "wp_posts.menu_order ASC";
    	} 	
            $text .= ' •  ' . $community->post_title .  ' •  Lot:  ' . $lot . '  •  SqFt:  ' . $sqft . ' •  MLS: ' . $mls . ' •  Price:  ' . $price . '';
        }
        return $text;
    }
  • Ok thanks for the information, I will have to explore this once I get their new website done. They can at least search by the title of the posts. Not ideal, especially for real estate with Beds, Baths, MLS number, lot number etc. Lots of other data they can search within posts to find the one they want to select! I WISH for ACF to include this natively please. The question is, why not? It would make our lives easier and especially the clients lives. Allow this additional search functionality to be enabled when we create the Post Object in the ACF field group settings. The settings for this feature would show all available custom field data, including WP native ones and allow us to select which we’d like the client to search using.

  • The problem is solved! Had really nothing to do with the Fields. It had everything to do with the PHP code I wrote need this at the end:

    wp_reset_query(); // Restore global post data stomped by the_post().
    ?>
  • CSS Grid worked great for me and then I tweaked the wrapper and inner container from there, it was really convenient.

  • The following info for a custom field was listed in the “meta_value” field in phpmyadmin in the database. Does this mean that there is associated content with that particular custom field? It was a relationship field in ACF…

    a:2:{i:0;s:5:”11637″;i:1;s:5:”11463″;}

    All the rest for this particular custom field are showing the meta_value like this:

    field_6324efebf4a7a

    I’m trying to reconnect data to the currently used ACF fields. I messed up and renamed fields and deleted them and then created new and renamed again so it’s kinda ugly in the database lol It’s actually messing up my php code for showing specific content.

  • John, I created a separate Forum thread for this question but wanted to direct your attention to this. I need to enable to search this Post Object that this filter is set up on to allow to search more than just the post title but rather those custom fields such as sq ft, community, mls and price. This way the agents have an easier time finding the listing their looking for in the backend of WP.

    Here’s the link to the forum post: https://support.advancedcustomfields.com/forums/topic/search-custom-fields-not-just-post-title-in-relationship-post-object-field/

  • Thank you John, I did end up figuring this out today but I’m grateful that you’ve taken the time to reply with the fix. I was really at my wits end and it was crazy simple after I realized the correct syntax. I can’t believe how it’s always the simple little things that can make you pull your hair out lol.

  • Here’s the screenshot where you can see on the backend how it’s only outputting the Community: text string I manually typed into the filter.

Viewing 10 posts - 1 through 10 (of 10 total)