Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1217848

    I am trying to display some images and content or excerpt from the posts outside wordpress using PHP. Can you please share an example of how can I do it?

    The idea is a simple page that displays exactly featured full images by ID.

    Query the database or using require “wp-load.php”;.

    Show full featured image from post 3
    Show text from post 3

    Show full featured image from post 8

    Show full featured image from post 14
    Show text from post 14

    And so on.

    So with PHP how can I do it?

    I understand this is not completely enfold related, but maybe someone wants to help :)

    Thanks.

    #1220842

    Hey peterolle,

    Thank you for the inquiry.

    Have you tried using the WordPress REST API? You should be able to fetch posts or any available data from your WordPress installation to any platform using HTTP requests.

    // https://developer.wordpress.org/rest-api/reference/

    Best regards,
    Ismael

    #1220843

    Thank you Ismael, yes, but I am not being able to do it per ID.

    Show here just featured image from post 8, here text from post 34, etc…

    #1220884

    Hi,

    Please try adding following code to bottom of functions.php file

    function av_get_thumb_excerpt( $atts ) {
    	$a = shortcode_atts( array(
    		'id' => '',
    	), $atts );
    
    	$output = get_the_excerpt($a['id']); 
    	$output .= get_the_post_thumbnail($a['id']);
    
    	return $output;
    }
    add_shortcode( 'my_shortcode', 'av_get_thumb_excerpt' );

    Then you can use the shortcode as following

    [my_shortcode id="10"]

    and replace ID (10) depending on which post you would like to display. I attached the result in private content field :)

    Regards,
    Yigit

    #1220907

    Thank you Yigit.

    The problem here is that I need to display featured image and text outside WordPress. In a stand alone PHP file.

    #1220960

    Hi,

    Sorry I thought outside of the loop.

    Thank you Ismael, yes, but I am not being able to do it per ID.

    Show here just featured image from post 8, here text from post 34, etc…

    So back to that, you can use post ID’s as with wp/v2/posts/8?_embed and wp/v2/posts/34?_embed

    Best regards,
    Yigit

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