• When I customize a heading of the Query Loop block, the dynamic data filter in the WordPress core recognizes the Custom Post Type. I select the Post Meta option as the Content Source and in the Post Meta Field field I write the name of the custom field.

    With custom fields of text type, the content of the field is displayed, but with relationship type fields, the content is not displayed. The problem is with the relationship custom fields. In this case, it is a relationship type field to select several values ??that come from the CPT that I related to that custom field.

    Is there any recommendation to be able to display the content of custom relationship type fields?

Viewing 15 replies - 1 through 15 (of 16 total)
  • Plugin Support Alvind

    (@alvindcaesar)

    Hi there,

    The Query Loop block doesn’t have built-in support for relationship fields, but it is possible with a custom PHP snippet. Refer here:

    https://generate.support/topic/can-i-query-posts-from-an-acf-relationship-field/#post-111633

    Thread Starter oscargonzalezgrande

    (@oscargonzalezgrande)

    It didn’t work. I share a .gif of what happened. Did I make a mistake in some step? If not, is there another way?

    Plugin Support ying

    (@yingscarlett)

    Can you share the screenshots links?It’s really hard to read of a gif, I haven’t finished reading it, it jumps to the next one.

    Thanks!

    Thread Starter oscargonzalezgrande

    (@oscargonzalezgrande)

    Sorry. I thought it might be a good idea to use a .gif file but it wasn’t. I hope it worked now.

    Plugin Support Alvind

    (@alvindcaesar)

    Replace the linked_consultants to your relationship field name, which in you case is autor_relationship

    Thread Starter oscargonzalezgrande

    (@oscargonzalezgrande)

    Thanks for your answer. But I changed linked_consultants to autor_relationship, and nothing happened. The content of the custom field is not displayed.

    That is the code I added in the functions.php file of the child theme:

    add_filter( 'generateblocks_query_loop_args', function( $query_args, $attributes ) {

    if (

    ! empty( $attributes['className'] ) &&

    strpos( $attributes['className'], 'related-profiles' ) !== false &&

    ! is_admin()

    ) {

    // get the relate post ID

    $current_post = get_the_ID() ;

    $relationship = get_field( "autor_relationship", $current_post );

    // Merge the current $query_args with the new args

    return array_merge( $query_args, array(

    'post__in' => $relationship,

    ) );

    }

    return $query_args;

    }, 10, 2 );
    Plugin Support ying

    (@yingscarlett)

    The query loop is added to the page called Queryloop Relationship_field, so this is the page where the query loop gets the relation, but it seems the page does not have relationship field, is that the case?

    Just so you know, the query loop should be added to the page/cpt where the relationship field is added.

    Thread Starter oscargonzalezgrande

    (@oscargonzalezgrande)

    I did it by creating a new page where the custom post type to which the relationship custom field belongs is and it didn’t work either.

    Plugin Support ying

    (@yingscarlett)

    Can I see screenshots of your current set up?

    Thread Starter oscargonzalezgrande

    (@oscargonzalezgrande)

    Set up:

    Plugin Support Alvind

    (@alvindcaesar)

    To see if the $relationship returns any data, could you try this:

    Below this line:

    $relationship = get_field( "autor_relationship", $current_post );

    Add this:

    var_dump($relationship);

    This will dump that variables value to the page, so we can then see what is inside it.

    Thread Starter oscargonzalezgrande

    (@oscargonzalezgrande)

    Hi, this is what happened:

    Plugin Support ying

    (@yingscarlett)

    I went through all the screenshots, and I don’t think you understand the relationship fields well. The relationship field can not be pulled via a headline block, as it returns array, which are posts, but it can be pulled by a query loop block.

    The relationship fields is to return posts/pages/cpt that are related to the current page/post/cpt.

    The query loop is to show the posts that are related to the page it is located in, so in your case, the query loop is supposed to show posts that are related to the page called “Query loop”.

    Hope that’s understandable.

    Thread Starter oscargonzalezgrande

    (@oscargonzalezgrande)

    The relationship custom field works outside of the query loop.

    With the help of this tutorial and chatgpt I applied a code to the CPT Publications single (CPT in which it has the relationship field within the group of fields), the values ??of that field are shown (the names and surnames of the authors).

    And what I would like to achieve is that those values ??were displayed using the QueryLoop of GenerateBlocks.

                   <?php $autor_relationship = get_field('autor_relationship');

    if ($autor_relationship) {
    $autor_titles = array();
    foreach ($autor_relationship as $autor_relationships) {
    $autor_titles[] = $autor_relationships->post_title;
    }
    echo implode('; ', $autor_titles);
    }

    ?>
    Thread Starter oscargonzalezgrande

    (@oscargonzalezgrande)

    And if I apply the var_dump that was recommended to me for the query loop in the single.

    var_dump($autor_relationship);

    This appears on the single:

    Fernández Vilas, Ana; Saquicela Galarza, Víctor H.; Zanovello, Paolaarray(3) { [0]=> object(WP_Post)#1944 (24) { [“ID”]=> int(12) [“post_author”]=> string(1) “1” [“post_date”]=> string(19) “2024-05-27 19:15:48” [“post_date_gmt”]=> string(19) “2024-05-27 19:15:48” [“post_content”]=> string(0) “” [“post_title”]=> string(21) “Fernández Vilas, Ana” [“post_excerpt”]=> string(0) “” [“post_status”]=> string(7) “publish” [“comment_status”]=> string(6) “closed” [“ping_status”]=> string(6) “closed” [“post_password”]=> string(0) “” [“post_name”]=> string(19) “fernandez-vilas-ana” [“to_ping”]=> string(0) “” [“pinged”]=> string(0) “” [“post_modified”]=> string(19) “2024-05-27 19:15:48” [“post_modified_gmt”]=> string(19) “2024-05-27 19:15:48” [“post_content_filtered”]=> string(0) “” [“post_parent”]=> int(0) [“guid”]=> string(49) “https://grupogsii.local/autor/fernandez-vilas-ana/&#8221; [“menu_order”]=> int(0) [“post_type”]=> string(5) “autor” [“post_mime_type”]=> string(0) “” [“comment_count”]=> string(1) “0” [“filter”]=> string(3) “raw” } [1]=> object(WP_Post)#1941 (24) { [“ID”]=> int(95) [“post_author”]=> string(1) “1” [“post_date”]=> string(19) “2024-05-27 19:17:11” [“post_date_gmt”]=> string(19) “2024-05-27 19:17:11” [“post_content”]=> string(0) “” [“post_title”]=> string(29) “Saquicela Galarza, Víctor H.” [“post_excerpt”]=> string(0) “” [“post_status”]=> string(7) “publish” [“comment_status”]=> string(6) “closed” [“ping_status”]=> string(6) “closed” [“post_password”]=> string(0) “” [“post_name”]=> string(26) “saquicela-galarza-victor-h” [“to_ping”]=> string(0) “” [“pinged”]=> string(0) “” [“post_modified”]=> string(19) “2024-05-27 19:17:11” [“post_modified_gmt”]=> string(19) “2024-05-27 19:17:11” [“post_content_filtered”]=> string(0) “” [“post_parent”]=> int(0) [“guid”]=> string(56) “https://grupogsii.local/autor/saquicela-galarza-victor-h/&#8221; [“menu_order”]=> int(0) [“post_type”]=> string(5) “autor” [“post_mime_type”]=> string(0) “” [“comment_count”]=> string(1) “0” [“filter”]=> string(3) “raw” } [2]=> object(WP_Post)#1943 (24) { [“ID”]=> int(148) [“post_author”]=> string(1) “1” [“post_date”]=> string(19) “2024-05-27 19:18:04” [“post_date_gmt”]=> string(19) “2024-05-27 19:18:04” [“post_content”]=> string(0) “” [“post_title”]=> string(16) “Zanovello, Paola” [“post_excerpt”]=> string(0) “” [“post_status”]=> string(7) “publish” [“comment_status”]=> string(6) “closed” [“ping_status”]=> string(6) “closed” [“post_password”]=> string(0) “” [“post_name”]=> string(15) “zanovello-paola” [“to_ping”]=> string(0) “” [“pinged”]=> string(0) “” [“post_modified”]=> string(19) “2024-05-27 19:18:04” [“post_modified_gmt”]=> string(19) “2024-05-27 19:18:04” [“post_content_filtered”]=> string(0) “” [“post_parent”]=> int(0) [“guid”]=> string(45) “https://grupogsii.local/autor/zanovello-paola/&#8221; [“menu_order”]=> int(0) [“post_type”]=> string(5) “autor” [“post_mime_type”]=> string(0) “” [“comment_count”]=> string(1) “0” [“filter”]=> string(3) “raw” } }

Viewing 15 replies - 1 through 15 (of 16 total)
  • You must be logged in to reply to this topic.