Support Forum

Please login to receive premium support.

Support for the free plugin can be found here.

Search Results for 'get_post_meta'

Home Forums Search Search Results for 'get_post_meta'

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

    • This topic was modified 2 days, 6 hours ago by Sebastian.
    #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!

    • This reply was modified 7 months, 2 weeks ago by Vlidi.
    #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%);
    }
    #23098
    P
    Participant

    Hi Elvin,

    Thank you for your previous suggestion. I ended up implementing the code below in the functions.php file:

    /* Add linkedin button in WPSP listing*/
    add_action( ‘wpsp_after_content’, function( $settings ) {
    if ( 10 === $settings[‘list_id’] ) {
    $meta = get_post_meta( get_the_ID(), ‘linkedin_profile’, true );
    if ( $meta ) {
    echo ‘<span><span class=”screen-reader-text”>%4$s</span></span>‘;
    }
    }
    } );

    I tried to use the fonts loaded with WPSP Pro, hoping i could load the linkedin icon, but i could not make it work. As such, i installed the FontAwesome plugin to get that icon, and ended up using the “fa” classes plus a custom “linkedin-button” for the styling. It’s maybe a bit overkill for just one icon 🙂

    I have one additional question, if i may: how can i load the same icon in the individual post entries? If it’s out of scope for this forum, just let me know!
    Thank you once again and best regards!

    #21950
    Samuel
    Participant

    Oh sorry, my bad, with the confusion of the our 2 different issues (redirection and translation) there was 2 functions conflicting, now it’s working, and here is the final word :

    <?php
    
    add_filter( 'wpsp_title_href', function( $href ) {
        $custom_url = get_post_meta( get_the_ID(), 'url-booking', true );
    
        if ( $custom_url ) {
            return $custom_url;
        }
    
        return $href;
    } );
    
    add_filter( 'wpsp_image_href', function( $href ) {
        $custom_url = get_post_meta( get_the_ID(), 'url-booking', true );
    
        if ( $custom_url ) {
            return $custom_url;
        }
    
        return $href;
    } );
    
    add_filter( 'wpsp_read_more_output', function( $output, $settings ) {
        $custom_url = get_post_meta( get_the_ID(), 'url-booking', true );
    
        if ( $custom_url ) {
            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' ),
                esc_url( $custom_url ),
                __( 'Voir les tarifs', 'wp-show-posts' ),
                esc_attr( $settings['read_more_class'] )
            );
        }
    
        return $output;
    }, 10, 2 );
    
    add_filter( 'wpsp_terms_output', function( $output ) {
        return strip_tags( $output );
    } );

    ?>`

    #21946
    Samuel
    Participant

    Hi Tom,

    Thanks again for your time, your support is amazing, but it’s not working. Here is the entire hook we are using combining custom redirection + read more translation :

    <?php
    
    add_filter( 'wpsp_title_href', function( $href ) {
        $custom_url = get_post_meta( get_the_ID(), 'url-booking', true );
    
        if ( $custom_url ) {
            return $custom_url;
        }
    
        return $href;
    } );
    
    add_filter( 'wpsp_image_href', function( $href ) {
        $custom_url = get_post_meta( get_the_ID(), 'url-booking', true );
    
        if ( $custom_url ) {
            return $custom_url;
        }
    
        return $href;
    } );
    
    add_filter( 'wpsp_read_more_output', function( $output, $settings ) {
        $custom_url = get_post_meta( get_the_ID(), 'url-booking', true );
    
        if ( $custom_url ) {
            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' ),
                esc_url( $custom_url ),
                __( 'Read more', 'wp-show-posts' ),
                esc_attr( $settings['read_more_class'] )
            );
        }
    
        return $output;
    }, 10, 2 );
    
    add_filter( 'wpsp_terms_output', function( $output ) {
        return strip_tags( $output );
    } );
    
    add_filter( 'wpsp_read_more_output', function( $output, $settings ) {
        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' ),
            esc_url( get_permalink() ),
            __( 'Voir les tarifs', 'wp-show-posts' ),
            esc_attr( $settings['read_more_class'] )
        );
    }, 10, 2 );
    
    ?>
Viewing 15 results - 1 through 15 (of 87 total)