Im working on a project where i upload a gpx file and use the path of gpx to put in a shortcode plugin i use the post id the get a filled in shortcode i use this code to get me the piece of info for the shortcode now i wanna make it so when i post a new post with the gpx file that it will automaticly gets the id and uses it im currently hard coded the id into it any1 has a fix for it?

global $wpdb; 
$thepost = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->postmeta WHERE post_id = 5574" ) );
echo do_shortcode ('[sgpx gpx="'.'/wp-content/uploads/' . $thepost->meta_value . '"]'); 

If the GPX file is attached to the current page you can find it with get_attached_media(), e.g.

$gpx_files = get_attached_media( 'application/gpx+xml' );
if ( count( $gpx_files ) >= 1 ) {
    echo do_shortcode ('[sgpx gpx="' . wp_get_attachment_url( $gpx_files[0]->ID ) . '"]');
} else {
    echo '<p class="warning">No GPX file attached!</p>';
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.