We're merging with GenerateBlocks! Learn more here.

Support Forum

Please login to receive premium support.

Support for the free plugin can be found here.

Home Forums Search Search Results for 'get_field'

Viewing 15 results - 1 through 15 (of 31 total)
  • Author
    Search Results
  • #37075
    Fernando
    Participant

    Yes, you can definitely do that in GB Query Loops.

    GenerateBlocks Headline Blocks have the capability to retrieve custom Post Meta texts.

    GenerateBlocks Image Blocks can also retrieve post meta images.

    You can integrate both of these Blocks within a GB Query Loop.

    In terms of code, you can also do this simply through the render_block filter as mentioned.

    So for instance, here’s a very simple sample for the first instance of centro_investigacion:

    function insert_centro_investigacion( $block_content, $block ) {
        if ( ! is_admin() && ! empty( $block['attrs']['className'] ) && 'my-custom-headline' === $block['attrs']['className']  ) {
    
    		$centro = get_field( 'centro_investigacion' );
    		
    		$my_replace = $centro[0];
                    $link = get_permalink( $my_replace );
                    $meta = get_the_title( $my_replace );
    		$block_content = '<br></br><a href=' . $link . ' target="_blank">' . $meta . '</a>';
    		
    		return  $block_content . ;
        } 
        return $block_content;
    }
     
    add_filter( 'render_block', 'insert_centro_investigacion', 10, 2 );

    Basically, if you have a Headline Block with class: my-custom-headline, you can replace the content, and add your custom text field as such.

    Another similar filter would be generateblocks_dynamic_content_output for dynamic GB Blocks.

    Hope this clarifies!

    #37073
    Xavier
    Participant

    Hi Fernando, it is not matter of styling the block or just pagination. It is the possibility to add, for example, custom information pulled off custom fields.

    For example, in a website I have used this snippet:

    add_action( 'wpsp_after_content', function( $settings ) {
        if ( 12 === $settings['list_id'] ) {
       $centro = get_field( 'centro_investigacion' );
       
       if ( $centro ) {
    echo '<b>Centre de recerca:</b> ';
       foreach ( $centro as $post_ids ) {
       $link = get_permalink( $post_ids );
       $meta = get_the_title( $post_ids );
       echo "<br></br><a href='$link' target='_blank'>$meta</a> ";
       
    }
    }         
    }
    } );
    
    add_action( 'wpsp_after_content', function( $settings ) {
        if ( 12 === $settings['list_id'] ) {
       $area = get_field( 'area_investigacion' );
       
       if ( $area ) {
    echo '<br></br><br></br><b>Γ€rea de recerca:</b> ';
       foreach ( $area as $post_ids ) {
       $link = get_permalink( $post_ids );
       $meta = get_the_title( $post_ids );
       echo "<br></br><a href='$link' target='_blank'>$meta</a> ";
       
    }
    }         
    }
    } );
    
    add_action( 'wpsp_after_content', function( $settings ) {
        if ( 12 === $settings['list_id'] ) {
       $proyectos = get_field( 'proyectos' );
       
       if ( $proyectos ) {
    echo '<br></br><br></br><b>Projectes:</b> ';
       foreach ( $proyectos as $post_ids ) {
       $link = get_permalink( $post_ids );
       $meta = get_the_title( $post_ids );
       echo "<br></br><a href='$link' target='_blank'>$meta</a> ";
       
    }
    }         
    }
    } );
    
    add_action( 'wpsp_after_content', function( $settings ) {
        if ( 12 === $settings['list_id'] ) {
            $meta = get_post_meta( get_the_ID(), 'enlace_a_orcid', true );
    		$meta2 = get_post_meta( get_the_ID(), 'enlace_researchgate', true );
    		$meta3 = get_post_meta( get_the_ID(), 'enlace_academia', true );
    		$meta4 = get_post_meta( get_the_ID(), 'enlace_grec', true );
           echo "<br></br><br></br>";
            if ( $meta ) {
                echo "<a href='$meta' target='_blank'><img src='https://ilercovid.com/wp-content/uploads/2021/07/orcid-logo.png'></a> ";}
    		if ( $meta2 ) {
    			echo "<a href='$meta2' target='_blank'><img src='https://ilercovid.com/wp-content/uploads/2021/07/logo-researchgate.png'></a> ";
            }
    		if ( $meta3 ) {
    			echo "<a href='$meta3' target='_blank'><img src='https://ilercovid.com/wp-content/uploads/2021/07/academia.png'></a> ";
            }
    		if ( $meta4 ) {
    			echo "<a href='$meta4' target='_blank'><img src='https://ilercovid.com/wp-content/uploads/2021/07/grec-logo.png'></a> ";
            }
    		
        }
    } );
    
    

    To achieve the result you see in this page:

    https://ilercovid.com/equip/

    My question is if this kind of hooks are still avaiable via block.

    Many thanks.

    #33813
    elvin
    Moderator

    Hi Sebastian,

    That’s actually doable.

    You can put things into the cards through WPSP hooks.

    Here’s a list of hooks where you can put your custom field values in.
    https://wpshowposts.com/support/topic/bbpress-metadata-and-dates-in-wpshowposts/#post-28854

    But you have to manually code them. Example:

    add_action('wpsp_after_title',function(){
    echo get_field('your_custom_field',get_the_ID());
    });
    #33426
    [Resolved]

    Topic: Add ACF to WPSP

    in forum Pro Support
    Zlatan
    Participant

    Hi,

    I am trying to show a badge on some of my posts in a wpsp list with the ID number 79. I have created a True/False ACF field called “multiple_images”.
    If the field is true I would like to hook the following code:
    <div class="badge"><span>Gallery</span></div>

    With PHP it would look something like this:

    <?php if ( get_field( 'multiple_images' ) ): ?>
    <div class="badge"><span>Gallery</span></div>
    <?php else: // field_name returned false ?>
    <?php endif; // end of if field_name logic ?>

    How exactly do I put it in the hook “wpsp_before_content”?

    I have tried this, but unfortunately it is not working:

    add_action( 'wpsp_after_content', function( $settings ) {
        if ( 79 === $settings['list_id'] ) 
    		
    <?php if ( get_field( 'multiple_images' ) ): ?>
    <div class="badge"><span>Gallery</span></div>
    <?php else: // field_name returned false ?>
    <?php endif; // end of if field_name logic ?>
    
    } );

    Thanks in advance,
    Zlatan

    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?

    #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.

    #30045
    elvin
    Moderator

    Hi there,

    I remember answering this question.

    And sorry about this but I believe I missed the context when I answered it. I thought the names of lists were posts lists of artists rather than a listing of categories.

    WPSP plugin can’t list categories directly. My bad. If you bought the plugin for this, you can ask for a request for a refund.

    But to help you out here’s something worth a try:

    Before you start, here are things to consider:

    Are the place labels going to be a taxonomy as well?

    If it isn’t, you’ll need ACF or some sort of custom fields plugin to save the places associated with the artist name.

    You then create your custom shortcode for this:

    Example: A custom category listing with artist_location field displayed on the side.

    add_shortcode('category_listing','category_listing_with_location');
    
    function category_listing_with_location(){
    echo '<ul class="category-list">';
    	
    $categories = get_categories( array(
        'orderby' => 'name',
        'order'   => 'ASC'
    ) );
     
    foreach( $categories as $category ) {
    	$acf_id = 'category_'.$category->term_id;
    	
        $category_link = sprintf( 
            '<a href="%1$s" alt="%2$s">%3$s</a> <span class="artist-location">%4$s</span>',
            esc_url( get_category_link( $category->term_id ) ),
            esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ),
            esc_html( $category->name ),
    				get_field('artist_location',$acf_id),
    			
        );  
        echo '<li class="category-list-item">' . $category_link . '</li> ';
    }  
    echo '</ul>';
    
    }

    This is a PHP snippet – here’s how to add one – https://docs.generatepress.com/article/adding-php/

    Note: we may need to style it with CSS to remove li styling.

    example:

    ul.category-list  {
      list-style: none;
    }

    Again, my bad.

    #28500
    Robert
    Participant

    Yessssss! I made it work with an action πŸ™‚

    here is the code:

    add_action( ‘wpsp_after_title’, ‘dht_custom_abstract_link’ );
    function dht_custom_abstract_link() {
    $link = get_field(‘speaker_in_abstract’);
    if( $link ):
    $link_url = $link[‘url’];
    $link_title = $link[‘title’];
    $link_target = $link[‘target’] ? $link[‘target’] : ‘_self’;
    ?>

    <div class=”speaker-info”>
    <p>Speaker:  </p>” target=”<?php echo esc_attr( $link_target ); ?>”><?php echo esc_html( $link_title ); ?>
    </div>
    <?php endif;
    }

    #28457
    Robert
    Participant

    The question:

    After searching and tweaking, fiddling and trying, I decided to ask my question on the forum πŸ™‚

    I have 2 custom post types;
    – Speaker
    – Abstracts (something the speaker said)

    The abstracts are shown in a 3 column grid on the homepage.

    My client asked if it’s possible to show the link to the speaker, under the title of the abstract. (as I would with a category or a tag).

    Normally I would connect those via a category or a tag, but as these are both custom post types, it’s not possible (out of the box) to make a relation between these 2 post types.

    In the ‘Abstract’ post, I made a custom field (link) with the Generatepress Elements/hooks, so I can select the url to the speaker, and show it on that particular ‘Abstract’ below the content.

    Now, my question;
    How can I show this same link (to the speaker of this abstract) under the title of the post type abstract?

    Examples:
    On the 3 column grid of this homepage, https://www.digitalhumanitiestilburg.com/

    The way the abstract should look (title, category – we are not going to use images here, so text only and no cards or any fancy layout)
    https://www.digitalhumanitiestilburg.com/speakers/

    I would like the same speaker-link as in: https://www.digitalhumanitiestilburg.com/abstracts/finding-the-human-in-the-dark-forest-perspectives-on-user-practices-outside-of-social-media-platforms/ (speaker is below the content, in the yellow box).

    I have also tried to place this same code below via a custom hook in generatepress, but it didn’t work (I cannot select the appropriate place for it to be shown.)

    The code I used for the custom link is this (and i’d like to ‘get’ the same link to show under the title of the abstracts):

    <div class=”speaker-wrapper”>
    <?php

    $link = get_field(‘speaker_in_abstract’);
    if( $link ):
    $link_url = $link[‘url’];
    $link_title = $link[‘title’];
    $link_target = $link[‘target’] ? $link[‘target’] : ‘_self’;
    ?>

    <div class=”speaker-info”>
    Speaker:  
    ” target=”<?php echo esc_attr( $link_target ); ?>”><?php echo esc_html( $link_title ); ?>
    </div>

    <?php endif; ?>
    </div>

    Hope you can help me out!
    Thanks in advance!

    #28455
    Robert
    Participant

    ok, i typed why because my post got rejected…. Too many words?

    here goes:

    After searching and tweaking, fiddling and trying, I decided to ask my question on the forum πŸ™‚

    I have 2 custom post types;
    – Speaker
    – Abstracts (something the speaker said)

    The abstracts are shown in a 3 column grid on the homepage.

    My client asked if it’s possible to show the link to the speaker, under the title of the abstract. (as I would with a category or a tag).

    Normally I would connect those via a category or a tag, but as these are both custom post types, it’s not possible (out of the box) to make a relation between these 2 post types.

    In the ‘Abstract’ post, I made a custom field (link) with the Generatepress Elements/hooks, so I can select the url to the speaker, and show it on that particular abstract below the content.

    Now, my question;
    How can I show this same link (to the speaker of this abstract) under the title of the post type abstract?

    Examples:
    On the 3 column grid of this homepage, https://www.digitalhumanitiestilburg.com/

    The way the abstract should look (title, category – we are not going to use images here, so text only and no cards or any fancy layout)
    https://www.digitalhumanitiestilburg.com/speakers/

    I would like the same speaker-link as in: https://www.digitalhumanitiestilburg.com/abstracts/finding-the-human-in-the-dark-forest-perspectives-on-user-practices-outside-of-social-media-platforms/ (speaker is below the content, in the yellow box).

    I have also tried to place this same code below via a custom hook, but it didn’t work (maybe I missed an important step or messed up the custom hook- which I found somewhere on the forum wpsp_below_title or something like that)

    The code I used for the custom link is this (and i’d like to ‘get’ the same link to show under the title of the abstracts):

    <div class=”speaker-wrapper”>
    <?php

    $link = get_field(‘speaker_in_abstract’);
    if( $link ):
    $link_url = $link[‘url’];
    $link_title = $link[‘title’];
    $link_target = $link[‘target’] ? $link[‘target’] : ‘_self’;
    ?>

    <div class=”speaker-info”>
    Speaker:  
    ” target=”<?php echo esc_attr( $link_target ); ?>”><?php echo esc_html( $link_title ); ?>
    </div>

    <?php endif; ?>
    </div>

    Hope you can help me out!
    Thanks in advance!

    #26900
    elvin
    Moderator

    There is any hook to put them inside the lightbox?

    There’s no hook within the lightbox gallery as the gallery img itself is generated by a script.

    I don’t think the previously provided solution would work well if the $field you have outputs an unordered list rather than a simple text caption string. The filter snippet was made for simple text strings for captions, not for inserting HTML structure.

    In that case, I think we need to do something else.

    Try doing this:

    Instead of inserting it as an attribute, lets hook it in on wpsp_inside_image_container as a content.

    add_action('wpsp_inside_image_container',function(){
    $field = get_field('your_acf_field_slug');
    echo $field;
    });

    After hooking it in, we can modify the script to fetch your unordered list and append it as caption.

    add_action( 'wp_footer', function () { ?>
    <script>
    	
    jQuery( document ).ready( function( $ ) {
        $.featherlightGallery.prototype.afterContent = function() {
            var caption = this.$currentTarget.find('img').parent().prev();
            this.$instance.find('.caption').remove();
            $('<div class="caption">').html(caption).appendTo(this.$instance.find('.featherlight-content'));
        };
    } );
    </script>
    
    <?php } );

    After this, we may have to style it with CSS. Let me know once you’ve done this so I could check and help out with the CSS write up.

    #26877
    elvin
    Moderator

    We can assign the custom field as <a> tags attribute by using the wpsp_image_data filter.

    add_filter('wpsp_image_data',function(){
    $field = get_field('your_acf_field_slug');
    return 'slick-caption="'.$field.'"';
    });

    This will add slick-caption="[acf_field_value]". We can fetch this as the caption for the featherlight image.

    After applying this filter, we can modify the script to take the slick-caption attribute value.

    add_action( 'wp_footer', function () { ?>
    <script>
    jQuery( document ).ready( function( $ ) {
        $.featherlightGallery.prototype.afterContent = function() {
            var caption = this.$currentTarget.find('img').parent().attr('slick-caption');
            this.$instance.find('.caption').remove();
            $('<div class="caption">').text(caption).appendTo(this.$instance.find('.featherlight-content'));
        };
    } );
    </script>
    <?php } );
    #24359
    elvin
    Moderator

    Could it be setup to pull an image via a custom field?

    Sure that’s possible.

    The code will look something like this:

    add_filter( 'post_thumbnail_html', 'my_post_thumbnail_fallback', 20, 5 );
    function my_post_thumbnail_fallback( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
        $fallback_image = get_field('fallback_image');
        if ( empty( $html ) ) {
            $html = sprintf( '<img src="%1$s" alt="%2$s" itemprop="image" class="%3$s" />',
                WPSP_Resize( $fallback_image, $image_atts[ 'width' ], $image_atts[ 'height' ], $image_atts[ 'crop' ], true, $image_atts[ 'upscale' ] )
                esc_attr( the_title() ),
                $settings[ 'image_alignment' ]
            );
        }
        return $html;
    }

    The fallback_image within get_field('fallback_image') is basically the slug of the fallback image custom field. This is assuming you’re using ACF.

    #23404
    elvin
    Moderator

    Hi,

    My apologies for the response delay.

    What I would like to know is since you created a lightweight social media section for WP Show Post is there a way to add this social media part only to Post pages globally using a hook?

    You can definitely place your own markup or lightweight social media shortcodes using the wpsp_after_content hook.

    Example:

    add_filter( 'after_setup_theme', function(){
    	remove_action( 'wpsp_after_content', 'wpsp_add_social_sharing', 10 );
    	add_action( 'wpsp_after_content', function(){
    		// do your thing here example: do_shortcode('[social_icon_widget_plugin_shortcode"]'); or echo get_field('sample_custom_acf_field');
    	}, 10 );
    });

    What this does is it removes the default social icons and replaces it w/ an action hooking whatever you add within the add_action( 'wpsp_after_content', function(){ // do something here });.

    #22885
    P
    Participant

    Hi Elvin,

    Thank you for your reply.
    I tried your instructions (see below). Before that, i also thought of a couple of possible alternatives. Maybe you have some thoughts on it?
    – I thought of using the “Lightweight social icons” plugin from Tom, thinking it would be simple. However, i could not get it to show in the WPSP view so i dropped it.
    – After looking at the plugin code, i also thought of simply extending the ” Show social sharing buttons” options by replicating and adapting the existing structure in the code. However, this would be lost with the next upgrade so i also dropped it πŸ™

    Following your instructions, I’ve started by using the ACF plugin to create an extra field called “linkedin__profile” (Type “Link”), to be used and displayed only in Posts of a certain category. The plugin also allows to assign a css class, which is handy.
    Since i’m using a child theme, I’ve added the php snippet above into the functions.php file, adapted as such:

    add_filter( ‘after_setup_theme’, function(){
    remove_action( ‘wpsp_after_content’, ‘wpsp_add_social_sharing’, 10 );
    add_action( ‘wpsp_after_content’, function(){echo get_field(‘linkedin__profile’);
    }, 10 );
    });

    However, i’m still not managing to display it correctly in the WPSP view (or in the single post itself, but that’s another thing). It either shows “Array” or the url as plain text. I’ve seen this mentioned in this thread Custom fields, so i’m checking that more carefully since i’m not very experienced in this part πŸ™‚

    That’s is all for now. Thank you for your time and help,
    Paulo
    I’ll add the css through the “Customize > Additional CSS” path.

Viewing 15 results - 1 through 15 (of 31 total)