I think you’re going about it the wrong way.
You can use get_posts to get the attachments of the current post:
$args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' =>'any', 'post_parent' => $post->ID );
$attachments = get_posts($args);
if ($attachments) {
foreach ( $attachments as $attachment ) {
echo apply_filters( 'the_title' , $attachment->post_title );
the_attachment_link( $attachment->ID , false );
}
}
See http://codex.wordpress.org/Template_Tags/get_posts#Show_attachments_for_the_current_post
Related Posts:
- Is there a plugin that will override the “Error establishing a database connection” message? [closed]
- How to properly insert data into custom table via plugin
- How does WordPress handle MySQL row lock errors?
- How to empty wordpress custom post Database table
- insert data in database table from plugin with WP3.1
- How to run Two WordPress blogs with different themes and with single database and same content
- $wpdb->get_results leaking memory
- Plugins or Tutorials for displaying data from SQL-db on WP-page? [closed]
- Is it a bad practice to go directly to the mysql database while developing a plugin?
- Can I explicitly specify ENGINE=InnoDB in WordPress?
- Create custom column in post table in wordpress
- Custom database or Custom Post Types?
- Get the last post ID
- Add agenda items and notifications
- How to count number of records found in a database table?
- Taking WordPress table prefixes into account
- Changing BIGINT to INT
- WordPress register_activation_hook table creation not working
- How to add Edit | Delete button on rows?
- The plugin generated x characters of unexpected output, $wpdb not defined
- clean wp_options table unused rows
- greatest() function returns undefined property
- Get total number of comment of the posts written by an author
- How to write one comment and publish on every post using database or plugin?
- Make id column as AUTO INCREMENT on plugin activation
- Unable to create new database table upon plugin activation using dbDelta
- Saving Custom Post types and fields to a custom table
- When to use action hooks and plugins
- Plugin Options Not Saving to Database in WP 4.5
- Access WordPress database outside of WordPress
- How to create custom tables in WordPress using my own plugin?
- Help With MySQL to WPDB Query Conversion
- DROP TABLE with uninstall hook not working
- how to oauth1 Wp plug-in revoke/reset.?
- How can I perform high-level database merging for WordPress within continues delivery?
- How to remove traces from widget during uninstallation
- WordPress Backend HA (Automatic failover)
- Migrating to WordPress Recipe Plugin and Some SQL Issues
- WordPress Integration with Google Groups
- Multiple instance of data in plugin custom database table on plugin activation
- WordPress plugin creating database in localhost but not on real host
- “Master” WordPress Multisite – Database Sync
- Better ads plugin has 500.000 entries in wp_postmeta
- How to create multiple database tables on plugin activation?
- Does deleting a Plugin via the WordPress admin ‘completely’ remove the code?
- Creating a CSV with PHP inside the plugin directory
- after wordpress update to 3.5+ i get many errors in plugin wpdb::prepare()
- How to keep variable `$post` to using in another file
- Best/Correct way to add an option to a category
- How to create plugin/ page that reads from database
- DB Query not working in Plugin
- Assign all Post in Wp to a specific Category
- Storing The Data Collected by Ninja Forms into Another (custom) Database [closed]
- Where do plugin variables live in the db?
- Plugin: connect to external database without showing password
- WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version [closed]
- Storing Form data in a different database
- More than one WordPress site using the same database – how to disable plugin for one site?
- How to make a Product page without ordering and database
- How to get specific column data conditionally in database in WordPress?
- How can I display selected content from a seperate database in an Activity style widget?
- What database state changes happen after a post is manually “updated” with no changes?
- Can i stream data to a custom_post_type?
- $wpdb->delete not working for me
- How do I add a medium to the WordPress database with my own plugin?
- Performing CRUD operations on front end in wordpress
- How to add specific script to WordPress webpage that will working with user input and databases
- I want to schedule email (date, time is in database->table) wp_schedule_event() not working
- How to use WordPress header function and footer function and not load word press database
- How to securely controlling data without keeping it in postmeta?
- $wpdb->insert not working inside save_post tag
- Get Shortcode output to database for static post_content
- Store GravityForm data in phpmyadmin (mysql)
- My wp database has been hacked
- How to update a database entry with a wordpress plugin?
- Accessing data from Google Cloud Datastore in WordPress site
- How can I store user preferences in WordPress and retreive them later?
- errno: 150 “Foreign key constraint is incorrectly formed” [closed]
- Database error when user logs in
- one admin for 2 wordpress websites
- database – multiple wordpress installations using same database – can they share plugin settings?
- HyperDB failover Delay
- Need help for creating custom table on wordpress
- Show a table from data submitted by a form from a user
- Create user assessment and use results in sql query
- WordPress custom posttype meta values doesnot save
- Posts are deleted everyday at night
- Display Plugin information on specific url
- Insert data in custom table during new post creation
- Managing database tables in WordPress multisite
- How to submit the custom form data in database in WordPress without plugin?
- Is it safe to increase/alter the size of the wp_post.guid column from VARCHAR(255) to VARCHAR(2048)?
- Duplicator live to wamp https to http
- Website keeps going down, is it a plugin, database, memory problem, or something else?
- Is it possible to recover Deleted users?
- User register hook can’t access form request
- On the same site, how do I send data from a plugin file to a theme file?
- Does anyone recognize these table names?
- Edit a page/post DB data?
- How do I set WordPress to send 2 different emails based on criteria in the database when someone submits a form?