Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7080055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:44:52+00:00 2026-05-28T06:44:52+00:00

Stuck with a WordPress query… It’s proably obvious what i’m trying to do…. But

  • 0

Stuck with a WordPress query…
It’s proably obvious what i’m trying to do…. But one line i just can’t work out, and can’t find any online info about it…

I’ve marked the excerpt line of code which i believe is causing the problems. What would be the correct reference for the excerpt?

$posts = get_posts(array(
'numberposts' => 2,
'post_type' => 'page',
'meta_key' => 'front_page_feature',
'meta_value' => '1'
));

if($posts)
{
echo '<ul>';

foreach($posts as $post)
{
    echo '<li><article><a href="' . get_permalink($post->ID) . '"><h2>' . get_the_title($post->ID) . '</h2>';
    $excerpt = get_post_excerpt($post->ID); <<<<<<<<<<<<----- HERE
    if (strlen($excerpt) > 135) {
    $excerpt = substr($excerpt, 0, 135) . '...';
            }
echo '<p>'. $excerpt .'</p>';
    echo '</a></article></li>';
}

echo '</ul>';
}

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:44:53+00:00Added an answer on May 28, 2026 at 6:44 am

    I might be wrong but isn´t the $post variable in the foreach an object?
    If so you could do $post->post_excerpt;

    EDIT:
    After looking more into it I´ve found that this won´t work.
    But you can easily adjust your script to work the way you want it to.

    foreach($posts as $post){
        setup_postdata($post);
        $excerpt = get_the_excerpt(); 
    
        if (strlen($excerpt) > 135) {
           $excerpt = substr($excerpt, 0, 135) . '...';
        }
    
        printf(
            '<li><article><a href="%s"><h2>%s</h2><p>%s</p></a></article></li>', 
            get_permalink(), 
            get_the_title(),
            $excerpt
        );
    }
    

    I´ve not tested it, but it should work.

    In the example on the get_post page you can see how the setup_postdata is used.

    Also note, that it says on the get_the_excerpt page that the parameter of the function is deprecated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out whether wordpress can handle the following requirements for a
Am a bit stuck with a wordpress loop, am wondering if anyone can help.
I am stuck trying to figure out a way of checking if a user
I just did a fresh install of WordPress 3.2.1. I've uploaded and activated one
Really stuck on trying to write code to unzip a file or directory on
I'm stuck with .Net 1.1 application (i.e. I can not use the generics goodies
I'm kinda stuck with this one so I hoped someone could help me. I
I have been making a wordpress template. i got stuck at some place... the
I'm getting very stuck on something that should be very easy. I am trying
I'm writing a Wordpress plugin which injects a grid of images just above the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.