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 8903445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:52:20+00:00 2026-06-15T01:52:20+00:00

I wrote this Query: $album_id = get_the_id(); $photos = $wpdb->get_results( select * from wp_postmeta

  • 0

I wrote this Query:

$album_id = get_the_id();
$photos = $wpdb->get_results(
    "select * from wp_postmeta where post_id = '"
    . $album_id
    . "' AND meta_key = 'gallery_ph' order by meta_id desc"
);

Now, I want to get all thumbnails with title, name and description for this images.

I found in the DB:

meta_id | post_id | meta_key   | meta_value
577     | 346     | gallery_ph | http://url to the image

and the thumbnail

meta_id | post_id | meta_key                 | meta_value
569     | 348     | _wp_attachment_image_alt | Jury Datiop

How are this two datas connected? I know that Jury Datiop has the url http://xxx because I can check in wp-admin. But how to write the select query? How to connect image and get title, name, description?

  • 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-06-15T01:52:21+00:00Added an answer on June 15, 2026 at 1:52 am

    You don’t need to query the database directly.

    WordPress has a whole lot of custom functions for you to retrieve the data that you need.

    Check the:

    WordPress Codex : Function Reference

    Specially:

    • get_posts
    • get_children
    • wp_get_attachment_metadata

    Translation of your database query to a WordPress function:

    code not tested, use the Debug to inspect the results of each operation

    $album_id = get_the_id();
    
    $photos = get_children( array(
        'post_parent'    => $album_id, 
        'post_type'      => 'attachment', 
        'meta_key'       => 'gallery_ph', 
        'post_mime_type' => 'image', 
        'order'          => 'DESC', 
        'orderby'        => 'meta_id') 
    );
    
    // DEBUG
    // echo '<pre>' . print_r( $meta, true ) . '</pre>';
    
    if( $photos )
    {
        foreach( $photos as $img )
        {
            // DEBUG
            // echo '<pre>' . print_r( $img, true ) . '</pre>';
    
            $meta = wp_get_attachment_metadata( $img->ID );
            
            // DEBUG
            // echo '<pre>' . print_r( $meta, true ) . '</pre>';
        }
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a query in this format.. Select * INTO #xyz FROM () which
I wrote this query: SELECT * INTO #nima FROM Region r Every time I
i wrote this query, but it gives me an error: select c.sid from catalog
I wrote this query : SELECT * FROM etape_prospection INNER JOIN type_prospection ON etape_prospection.type_prosp_id
I wrote this sql query to search in a table: SELECT * FROM TableName
I wrote this query: INSERT INTO KeysTable (KeyText, Id) SELECT KeyText as BKT, KeysTable.ID
I want to extract the parameters names from a query like this: select *
In access I wrote this query: Select I.sysid, I.MemberNumber, I.Date, I.Distributer, F.MemberNumber as FMember,
I'm using nHibernate 3.2.0.4000. I wrote this query using nHibernate.Linq var entities = (from
Is it possible to write this query in codeigniter active records? $Main_Nav_Query = mysql_query(SELECT

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.