[Support request] Show related posts create with Advanced Custom Fields in card

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Pro Support Show related posts create with Advanced Custom Fields in card

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #31972
    Xavier
    Participant

    Hi, after testing with the plugin I achieved to show custom taxonomies and acf in the cards using the code found in this forum.

    But now I have issues trying to show a concrete acf.

    What I want to achieve?
    I want to show the name of and ACF of relation between posts. For example: House – Name of vendors
    I want that each name appeared linked to the each post: For example: Each vendor linked to his page.

    Until now, if I use this code I just achieve to show the IDs of the posts:

    add_action( 'wpsp_before_content', function( $settings ) {
        if ( 12 === $settings['list_id'] ) {
            $metas = get_post_meta( get_the_ID(), 'proyectos', true );
    
            if ( $metas ) {
    			 foreach( $metas as $meta ){
                echo $meta;
    			 echo ' ';}
            }
        }
    } );

    Just in case it could be helpful, to show the array properly in the post page I use this code and it works fine:

    <?php $proyectos = get_field( 'proyectos' ); ?>
    <?php if ( $proyectos ) : ?>
    	<?php foreach ( $proyectos as $post_ids ) : ?>
    		<a href="<?php echo get_permalink( $post_ids ); ?>"><?php echo get_the_title( $post_ids ); ?></a>
    	<?php endforeach; ?>
    <?php endif; ?>

    Many thanks in advance.

    #32002
    elvin
    Moderator

    Hi there,

    I’m not exactly sure what you’re trying to get but I think what you need is get_field_object('my_field');.

    I see you need to fetch the name or label of the field. In that case, you can use this as reference – https://www.advancedcustomfields.com/resources/get_field_object/

    I’m not exactly sure about relation between posts though as I’m not sure how you’ve assigned relationships between them or what kind of relationship do you want to get.

    Is it relationship by which category they belong to? post tags? relationship by the author?

    #32010
    Xavier
    Participant

    Hi Elvin, I show you the result I have achieved in both cases with an image. The result in the content (achieved with the second code) is what we want in the wp show posts (now just shows the ID).

    Example

    How I should modify the first code to achieve this result?

    Thanks!

    #32059
    Xavier
    Participant

    ¡Solved!

    #32090
    elvin
    Moderator

    Sorry for getting back late.

    If you can get the ID, I believe you should be able to get the title from that ID.

    Glad you got it sorted. 😀

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.