Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author Frederik Rosendahl-Kaa

    (@frederik-rosendahl-kaa)

    Hi @claudeine,

    You can change how the plugin displays the data using this hook.
    The code just needs to be placed in your function.php file in the theme or child-theme.

    add_filter( 'acfvc_post_object', 'acfvc_custom_post_object_output', 10, 3 );
    function acfvc_custom_post_object_output ( $output, $field, $post_id ) {
    
    	return $output;
    }

    Best regards
    Frederik

    Thread Starter claudeine

    (@claudeine)

    Hi @frederik-rosendahl-kaa, thank a lot for your answer,

    Sorry for my ignorance but I don’t understand how to output 1 of the parameters of the Post Object. I’m doing this (I am not sure at all what I have done I am new to code) :

    add_filter( 'acfvc_post_object', 'acfvc_custom_post_object_output', 10, 3 );
    function acfvc_custom_post_object_output ( $output, $field, $post_id ) {
    	
    	$field = get_field('formation');
    	if( $field ): 
    		$ID = esc_html( $field->ID ) ;
    		$title = esc_html( $field->post_title ) ;
    		$permalink = get_permalink( $ID );
    		$thumbnail = '' ;
    		$custom_field = '' ;
    	endif;
    	
    	$output = '' ;
    
    	return $output;
    }

    But now how can I display the title sometimes, sometimes the permalink?
    Also I can’t save the post object thumbnail and a custom meta.

    Thank for your help.

    • This reply was modified 4 years, 2 months ago by claudeine.
    • This reply was modified 4 years, 2 months ago by claudeine.
    • This reply was modified 4 years, 2 months ago by claudeine.

    Hi! Having a similar Question:

    I’m using ACF to relate to a Custom Post Type (Relationship field). The Integrator works fine but the output is a simple link to the post.

    I added following code to my funktions.php:

    add_filter('acfvc_relationship','my_function',10,3);
    function my_function ( $output, $field, $post_id ) {
    return $output;}

    But the output is still just a link. Is it possible to show the text field or even the excerpt?

    Thanks in advance!

    • This reply was modified 4 years, 2 months ago by contixmedia.
    • This reply was modified 4 years, 2 months ago by contixmedia.
    • This reply was modified 4 years, 2 months ago by contixmedia.
    Thread Starter claudeine

    (@claudeine)

    @frederik-rosendahl-kaa please need your help ??

    Plugin Author Frederik Rosendahl-Kaa

    (@frederik-rosendahl-kaa)

    Hi @claudeine,

    Sorry I have not answered for some days but my day job is busy at the moment.
    But am not quite sure what you mean by display the title and permalink sometimes.

    But the way you can output for example the title as a link is something like this.

    $output = '<a href="'.$permalink.'">'.$title.'</a>';
    
    return $output;

    Hope this can help you
    Best regards
    Frederik

    Plugin Author Frederik Rosendahl-Kaa

    (@frederik-rosendahl-kaa)

    Hi @contixmedia,

    Yes it is possible to view excerpt, I have made 2 examples for you.
    One is if you have chosen that you can only select one entry in your post object field the other example is if you have done so you can select more in one entry

    /*Single post object */
    add_filter( 'acfvc_post_object', 'acfvc_custom_post_object_output', 10, 3 );
    function acfvc_custom_post_object_output ( $output, $field, $post_id ) {
    
    	$ttile = $field["value"]->post_title;
    	$content = apply_filters( "the_content", $field["value"]->post_content );
    	$excerpt = $field["value"]->post_excerpt;
    
    	$output = $excerpt.'<br>'.$content.'<br>'.$ttile;
    
    	return $output;
    }
    
    /*multiple post object */
    add_filter( 'acfvc_post_object', 'acfvc_custom_post_object_output', 10, 3 );
    function acfvc_custom_post_object_output ( $output, $field, $post_id ) {
    
    	$output = '';
    
    	foreach ($field["value"] as $key => $value) {
    		$ttile = $value->post_title;
    		$content = apply_filters( "the_content", $value->post_content );
    		$excerpt = $value->post_excerpt;
    
    		$output .= $excerpt.'<br>'.$content.'<br>'.$ttile;
    	}
    
    	
    
    	return $output;
    }

    Hope this can help you
    Best regards
    Frederik

    Thread Starter claudeine

    (@claudeine)

    @frederik-rosendahl-kaa No worries, I understand for your work.

    I mean the $output is necessarily the same for all the “acfvc_post_object” blocks it uses, but sometimes with this same object I would need to display the title of the post, while others I would need to display its thumbnail.

    By the way you didn’t tell me how to get the thumbnail and a custom meta of the linked post as I did for the title or the permalink, I did not succeed.

    Would you also have a list of the different filters available for the different blocks available?

    Thank you again for your precious help.
    Regards

    @frederik-rosendahl-kaa:

    You made my day!
    Thank you so much!

    Thread Starter claudeine

    (@claudeine)

    @frederik-rosendahl-kaa I imagine you are busy with work and I apologize for insisting but I am really stuck in my project and I need your help on these points:

    I mean the $output is necessarily the same for all the “acfvc_post_object” blocks it uses, but sometimes with this same object I would need to display the title of the post, while others I would need to display its thumbnail.

    By the way you didn’t tell me how to get the thumbnail and a custom meta of the linked post as I did for the title or the permalink, I did not succeed.

    Would you also have a list of the different filters available for the different blocks available?

    Regards

    Plugin Author Frederik Rosendahl-Kaa

    (@frederik-rosendahl-kaa)

    Hi @claudeine, I’m trying to look at it tonight when I get home from work.

    Thread Starter claudeine

    (@claudeine)

    @frederik-rosendahl-kaa Thanks a lot !

    Thread Starter claudeine

    (@claudeine)

    @frederik-rosendahl-kaa I will explain you my situation, maybe It can help you to understand and solve my probs.

    1- I have a custom post type : “Teacher” where I have Title (name of the teacher), Thumbnail (his picture) and custom ACF Meta link “Facebook” (his facebook page URL).

    2- I have a second custom post type : “Workshop” where I have Title (name of the workshop) Thumbnail (his picture), expert (his program) and a custom ACF Meta Post Object “Teacher” (where we select 1 or more post of my previous custom post type).
    So I need to display, on Workshop page, the teachers (because there can be several) and their information with your “acfvc_post_object”.

    3- But then I have a third custom post type : “Session” where I have a custom ACF meta date picker “Date” and a custom ACF Meta Post Object “Workshop” (where we select only one of the previous custom post type).
    And I need to display on the Session page the workshop name, thumbnail and link with your “acfvc_post_object”.

    So If I made filter for the “acfvc_post_object” for my custom post type “Workshop” he doesn’t work for my custom post type “Session”.
    And I’m still unable to recover thumbnail and custom meta in the “acfvc_post_object” filter.

    Hope this help you to understand.

    • This reply was modified 4 years, 2 months ago by claudeine.
    Plugin Author Frederik Rosendahl-Kaa

    (@frederik-rosendahl-kaa)

    Hi @claudeine,

    I have made 2 examples for you.
    The first is if you have only made it possible to select 1 post in your post object field, the second is if you have allowed multiple posts to be selected.

    Where it says post_object_field_name_1 and post_object_field_name_2 this is the name of your post object field and this allows you to change the content only for the specific field output.
    The reason I added 2 was because you wrote you have 2 different ones.
    You can add more and delete so you only have one.
    But post_object_field_name_1 and post_object_field_name_2 just need to be changed to the names of your post obejct fields.

    Where it says custom_field_name_1 and custom_field_name_2 here you can insert the name of your custom field you want to retrieve.
    You can read more about it here https://www.advancedcustomfields.com/resources/get_field/

    /*Example 1 - Single post object */
    add_filter( 'acfvc_post_object', 'acfvc_custom_post_object_output', 10, 3 );
    function acfvc_custom_post_object_output ( $output, $field, $post_id ) {
    
    	if ( $field["name"] == "post_object_field_name_1" ) {
    
    		$ttile = $field["value"]->post_title;
    		$thumbnail = get_the_post_thumbnail( $value["value"]->ID, 'full');
    		$custom_field = get_field( 'custom_field_name', $value["value"]->ID );
    
    		$output .= $ttile.'<br>'.$thumbnail.'<br>'.$custom_field;
    	}
    
    	if ( $field["name"] == "post_object_field_name_2" ) {
    
    		$ttile = $field["value"]->post_title;
    		$thumbnail = get_the_post_thumbnail( $value["value"]->ID, 'full');
    		$custom_field = get_field( 'custom_field_name_2', $value["value"]->ID );
    
    		$output .= $ttile.'<br>'.$thumbnail.'<br>'.$custom_field;
    	}
    
    	return $output;
    }
    
    /*Example 2 - multiple post object */
    add_filter( 'acfvc_post_object', 'acfvc_custom_post_object_multiple_post_output', 10, 3 );
    function acfvc_custom_post_object_multiple_post_output ( $output, $field, $post_id ) {
    
    	$output = '';
    
    	if ( $field["name"] == "post_object_field_name_1" ) {
    
    		foreach ($field["value"] as $key => $value) {
    			$ttile = $value->post_title;
    			$thumbnail = get_the_post_thumbnail( $value->ID, 'full');
    			$custom_field = get_field( 'custom_field_name', $value->ID );
    
    			$output .= $ttile.'<br>'.$thumbnail.'<br>'.$custom_field;
    		}
    	}
    
    	if ( $field["name"] == "post_object_field_name_2" ) {
    
    		foreach ($field["value"] as $key => $value) {
    			$ttile = $value->post_title;
    			$thumbnail = get_the_post_thumbnail( $value->ID, 'full');
    			$custom_field = get_field( 'custom_field_name_2', $value->ID );
    
    			$output .= $ttile.'<br>'.$thumbnail.'<br>'.$custom_field;
    		}
    	}
    
    	return $output;
    }

    Hope this can help you

    Best regards
    Frederik

    • This reply was modified 4 years, 1 month ago by Frederik Rosendahl-Kaa. Reason: Added Example 1 and 2 to code example
    Thread Starter claudeine

    (@claudeine)

    @frederik-rosendahl-kaa Awesome! You are perfect. I’m going to test all of this tomorrow but I think it will indeed help me.
    Thank you again for your help.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Post object output’ is closed to new replies.