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

  • SEARCH
  • Home
  • 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 690091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:24:00+00:00 2026-05-14T02:24:00+00:00

I am trying to modify a wordpress / MySQL function to display a little

  • 0

I am trying to modify a wordpress / MySQL function to display a little more information. I’m currently running the following query that selects the post, joins the ‘postmeta’ and gets the info where the meta_key = _liked

    function most_liked_posts($numberOf, $before, $after, $show_count) {
 global $wpdb;

    $request = "SELECT ID, post_title, meta_value FROM $wpdb->posts, $wpdb->postmeta";
    $request .= " WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id";
    $request .= " AND post_status='publish' AND post_type='post' AND meta_key='_liked' ";
    $request .= " ORDER BY $wpdb->postmeta.meta_value+0 DESC LIMIT $numberOf";
    $posts = $wpdb->get_results($request);

    foreach ($posts as $post) {
     $post_title = stripslashes($post->post_title);
     $permalink = get_permalink($post->ID);
     $post_count = $post->meta_value;

     echo $before.'<a href="' . $permalink . '" title="' . $post_title.'" rel="nofollow">' . $post_title . '</a>';
  echo $show_count == '1' ? ' ('.$post_count.')' : '';
  echo $after;
    }
}

The important part being: $post_count = $post->meta_value;

But now I want to also grab a value that is attached to each post called wbphoto

How do I specify that
$post_count = _liked and
$photo = wbphoto

?

Here is a screen cap of my Phpmyadmin
alt text

  • 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-14T02:24:00+00:00Added an answer on May 14, 2026 at 2:24 am

    The SQL will look very ugly.

    // Your Meta key names
        $metas = array(
            '_liked', '_another1'
        );
    
        foreach ($metas as $i=>$meta_key) {
            $meta_fields[] = 'm' . $i . '.meta_value as ' . $meta_key;
            $meta_joins[] = ' left join ' . $wpdb->postmeta . ' as m' . $i . ' on m' . $i . '.post_id=' . $wpdb->posts . '.ID and m' . $i . '.meta_key="' . $meta_key . '"';
        }
        $request = "SELECT ID, post_title, " .  join(',', $meta_fields) . " FROM $wpdb->posts ";
        $request .=  join(' ', $meta_joins);
        $request .= " WHERE post_status='publish' AND post_type='post'";
        $request .= " LIMIT $numberOf";
    

    It will be better of making another SQL to retrieve meta themselves.

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

Sidebar

Related Questions

I'm trying to modify my wordpress theme (inove) to display all comments in the
I'm trying to modify the following rewrite conditions so that only strings that begin
I'm trying to modify the following query to find the rank of a specific
I have a javascript file from a wordpress plugin that I'm trying to modify.
I'm trying to slightly modify a wordpress template. At the moment a function returns
I'm trying to modify the following code so that it will return a Dictionary<int,int>
I am trying to develop a query for WordPress that will allow me to
I am trying to modify the script below to click a button that looks
Right now I'm trying to modify the motion theme for Wordpress. As of now
I'm trying to modify some exports. I understand that this code doesn't work because

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.