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_post_meta'

Viewing 15 results - 1 through 15 (of 90 total)
  • Author
    Search Results
  • #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.

    #36673
    Ema
    Participant

    Hello Fernando, I’m still a little stuck

    My ACF field is ‘start_date’ and my list id is ‘4943’.

    Would the code look like this below? Also – do I still add via shortcode, and add this function via my child theme?

    add_action( 'wpsp_before_content', function( $settings ) {
        if ( 4943 === $settings['list_id'] ) {
            $meta = get_post_meta( get_the_ID(), '_start_date', true );
    
            if ( $meta ) {
                echo $meta;
            }
        }
    } );

    All my CPT event posts have the ACF field of ‘start_date’ – how does this only show the current events.

    Many thanks in advance

    • This reply was modified 5 months, 2 weeks ago by Ema.
    • This reply was modified 5 months, 2 weeks ago by Ema.
    #36141
    elvin
    Moderator

    Ah that one!

    Try this.

    I wanted the “Read more” more link directly linking to the product link of the WooCommerce link. You gave me this code:

    add_filter( 'wpsp_read_more_output', function( $output, $settings ) {
    $productURL = get_post_meta( get_the_ID(),'_product_url', false ); 
    if( 1987 === (int) $settings["list_id"]){
        return sprintf(
            '<div class="wpsp-read-more"><a title="%1$s" class="%4$s" href="%2$s">%3$s</a></div>',
            the_title_attribute( 'echo=0' ),
            $productURL[0],
            __( 'Read more', 'wp-show-posts' ),
            esc_attr( $settings['read_more_class'] )
        );
    }
    
    return $output;
    }, 10, 2 );
    #33780
    [Support request]

    Topic: Feature Request: custom fields / meta

    in forum Pro Support
    Sebastian
    Participant

    It would be great to have the option to display the content of custom_fields in a card.

    get_post_meta($post->ID, '....', true);

    #33574
    elvin
    Moderator

    Let’s dig a bit deeper and do some checks.

    Can you do a var_dump() of the post’s post_meta?

    Sample code:

    $meta_values = get_post_meta( get_the_ID() );
    var_dump( $meta_values );

    Hook this on an existing hook on your theme’s single post page. This way we can see and fully verify the post meta in existence by going to a single post page with the supposed um_restriction_content meta.

    #33428

    In reply to: Add ACF to WPSP

    Zlatan
    Participant

    Actually I figured it out, I think.

    Used this code

    add_action( 'wpsp_before_header','wpsp_add_custom_meta' );
    function wpsp_add_custom_meta()
    {
        $meta = get_post_meta( get_the_ID(), 'multiple_images', true );
        if ( isset( $meta ) && '' !== $meta )
            echo '<div class="badge"><span>Gallery</span></div>';
    }

    and it works 🙂

    #32590

    In reply to: Excerpt as title

    Bernhard
    Participant

    Hi Tom,
    I have now the following code repeated for every involved post/page id:

    add_action( 'wpsp_after_content', function( $settings ) {
        $custom_field = get_post_meta( get_the_ID(), 'wpsp_title2', true );
    
        if ( $custom_field && 123 === $settings['list_id'] ) {
            echo '<h2>';
                echo $custom_field;
            echo '</h2>';
        }
    } );

    Is it possible to put all the Id’s in a unique array like ( 123, 124, 125 ) ?

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

    #30817
    Ushan
    Participant

    As per Tom’s answer somewhere else (sorry!) – this got it working.

    add_action( ‘wpsp_after_title’, function( $settings ) {
    if ( 321 === $settings[‘list_id’] ) {
    $meta = get_post_meta( get_the_ID(), ‘field-name’, true );

    if ( $meta ) {
    echo $meta;
    }

    }
    } );

    Where 321 is the Show Posts list id. I was getting nowhere because I was putting the category ID in. 😀

    #29102
    elvin
    Moderator

    Use the wpsp_date_output filter for the date.
    https://github.com/tomusborne/wp-show-posts/blob/35e410d7800273fc66f211c0f80d553e95d17f83/inc/functions.php#L91

    Try this out.

    add_filter('wpsp_date_output',function(){
        if ( 'tribe_events' == get_post_type() ) { 
    		$cpt_archive_link = get_post_type_archive_link( get_post_type( get_the_ID() ) );
    
            $startDate = strtotime( get_post_meta( get_the_ID(), '_EventStartDate', true ));			
    		$startDate = date( 'j.n.Y', $startDate );
    
            return sprintf('<div class="wpsp-post-type-name">
                            Event date: %1$s
                        </div>',
                        $startDate
                    );
        }
    });
    #29050
    Joon
    Participant

    It works! Thank you. I know this may be getting a bit out of hand but I ran into another issue with the list.

    I am listing both traditional posts and events (CPT) in the same list, but WPSP shows the publishing date of the post, as it should. But because I have an event, it would be more logical to show the date of the event instead.

    I already achieved a working code, so I am really close! The code checks if its the CPT with Events, and displays the date in the post like this: https://pasteboard.co/JWwd44z.png
    But would it be possible to replace the post-date with this code?

    if ( 'tribe_events' == get_post_type() ) {
    		echo '<div class="wpsp-post-type-name"><a href="'.$cpt_archive_link.'">'.$post_label.'</a></div>';	
    		$startDate = strtotime( get_post_meta( get_the_ID(), '_EventStartDate', true ));			
    		$startDate = date( 'j.n.Y', $startDate );
    		echo 'Event date: ',$startDate;
                    }
    #28567
    Bernhard
    Participant

    Hi Elvin,
    my excuses, I linked to the wrong reply in the thread.

    Actually the excerpt is triggered by WPSP without additional code and the title is called from the custom field wpsp_title2 with this code.

    Adding the priority value to the title, it would look like this

    add_action( 'wpsp_after_content', function( $settings ) {
        $custom_field = get_post_meta( get_the_ID(), 'wpsp_title2', true );
    
        if ( $custom_field && 32293 === $settings['list_id'] ) {
            echo '<h2>';
                echo $custom_field;
            echo '</h2>';
        }
    }, 1 );

    but i don’t know how to trigger the excerpt priority in WPSP.

    #26221
    Vlidi
    Participant

    Hi Elvin, and thank you – this works great!

    So whoever may need it, the complete solution for using WPSP as Lightbox gallery WITH CAPTIONS:

    1. For the Gallery preview mode (e.g. thumbnails in Carousel):

    – Use this code (child theme / Code Snippets):

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

    – Style with this CSS:

    .caption {
    	background-color: #ffffff;
    	color: #aaaaaa;
    	padding: 5px;
    	font-size: 20px;
    }

    2. For the Gallery view mode in Lightbox;

    – Use this code (child theme / Code Snippets):

    add_action('wpsp_inside_image_container',function(){
    
    $image_id = get_post_thumbnail_id( get_the_ID(), 'full' );
    $image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', TRUE);
    
    $caption = '<div class="wpsp-img-caption">';
    $caption .= $image_alt;
    $caption .= '</div>';
    
    echo $caption;
    });

    – Style with this CSS:

    .wp-show-posts-image{
    position: relative;
    }
    .wp-show-posts-image .wpsp-img-caption{
    position: absolute;
    bottom: 2%;
    left: 50%;
    transform: translateX(-50%);
    }

    ***

    This works for WPSP 1.1.3 and WPSP Pro 1.0.

    Thank you once again for the fantastic support!

    #26189
    elvin
    Moderator

    Try this instead:

    add_action('wpsp_inside_image_container',function(){
    
    $image_id = get_post_thumbnail_id( get_the_ID(), 'full' );
    $image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', TRUE);
    
    $caption = '<div class="wpsp-img-caption">';
    $caption .= $image_alt;
    $caption .= '</div>';
    
    echo $caption;
    });

    I simply changed this $caption .= .$image_alt; into this: $caption .= $image_alt; so the stray . is removed.

    You then add this CSS:

    .wpsp-img-caption {
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
    }

    Here’s how it would look: https://share.getcloudapp.com/jkueoAgo

    You can see here that the alt text is in the image.

    Try it again with this fix and let us know how it goes.

    #26083
    elvin
    Moderator

    I’m still not sure I understand what you mean. You seem to be trying to turn the image lightbox into a carousel.

    I don’t think that’s possible with how WPSP’s script are written.

    And to be honest, this may require scripts which is out of the plugin support’s scope.

    As for putting the caption on the image, it should be possible by inserting it with wpsp_inside_image_container hook.

    Example: (using alt as caption.)

    Add this PHP:

    add_action('wpsp_inside_image_container',function(){
    
    $image_id = get_post_thumbnail_id( get_the_ID(), 'full' );
    $image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', TRUE);
    
    $caption = '<div class="wpsp-img-caption">';
    $caption .= .$image_alt;
    $caption .= '</div>';
    
    echo $caption;
    });

    Then add this CSS:

    .wp-show-posts-image{
    position: relative;
    }
    .wp-show-posts-image .wpsp-img-caption{
    position: absolute;
    bottom: 2%;
    left: 50%;
    transform: translateX(-50%);
    }
Viewing 15 results - 1 through 15 (of 90 total)