How do I add multiple post types to this query?
<?php if ( ‘pretty-little-liars’ == get_post_type() || ‘gallery’ == get_post_type() ) { // … } ?>
<?php if ( ‘pretty-little-liars’ == get_post_type() || ‘gallery’ == get_post_type() ) { // … } ?>
WordPress attachments are saved in the wp_posts table with the post_type field set to ‘attachment’. The post id for the post that the attachment is ‘linked’ to is in the post_parent field. Keep in mind that an attachment being ‘linked to a post is not really a solid connection. It is very possible to have … Read more
you have to edit your settings > permalinks
After changing your permalink structure, you need to refresh the settings in your Yoast plugin. After changing your WordPress permalink settings, go back to the Permalinks section for Yoast (Yoast SEO => Permalinks). Uncheck the box to “Redirect attachment URL’s to parent post URL.” Click Save. Check the box again. Click Save again. This should … Read more
Some people like to stream audio in the browser, others like to download. Each of them is able set up the browser to choose between downloading or streaming different MIME types to get what they need. On the other hand you can force download of certain MIME type files using PHP header() function. See How … Read more
You could use substr() Returns the portion of string specified by the start and length parameters. in combination with strrpos() Find the numeric position of the last occurrence of needle in the haystack string. Example $name = basename( wp_get_attachment_url( $post->ID ) ); echo substr( $name, 0, strrpos( $name, ‘.’ ) ); This will show the … Read more
I solved it. The problem was, that I called the function inside of another function, called later. The snippet in the question works like it should. I thought about deleting the question, but I think for other users, that are searching for a way to do something like that, the snippet would be interesting.
Have a look at wp_localize_script for passing php data to javascript. A pseudo-code example: $tracks = array(); foreach( $mp3_attachments as $mp3_attachment ): $tracks[] = array( ‘mp3’ => $mp3_attachment[‘filename’], ‘title’ => $mp3_attachment[‘title’] ); endforeach; $wpa_track_data = array( ‘tracks’ => $tracks ); wp_enqueue_script( ‘wpa_script’, get_template_directory_uri() . ‘/js/yourscript.js’ ); wp_localize_script( ‘wpa_script’, ‘wpa_data’, $wpa_track_data ); Then in your js … Read more
Ended up using wp_handle_upload(), which puts MIME type into the DB automatically. See http://codex.wordpress.org/Function_Reference/wp_handle_upload One thing to note, this function enters the file in the DB as post meta and not as an attachment. wp_insert_attachment() would do the latter.
A quick experiment with WordPress 3.5.1 shows that when you an image into post from URL, there’s no post inserted into the wp_posts or wp_postmeta table – which is why the $images array is coming back empty. You could write some JS on the admin side to create and insert a post asynchronously when you … Read more