I'm currently working on a project where we are using Wordpress 3.0 RC. The idea is to create custom post types with meta boxes to make the system easier to use for the client. Some of these posts need to have multiple files attached to them, and by attached I do not mean inserted to post but rather we'd like to keep them separate from the post body (in fact, a given post type might not even have text, only files).
I'm wondering if there is a standard approach for allowing multiple files to be attached to a Wordpress post? I've managed to add a meta box that allows one file from the media library to be selected, but I have no idea how to extend this to allow an arbitrary number of files. Hope someone can help!
When a user is writing a post, and proceeds to upload media, that media is automatically 'attached' to the current post.
However, unless the user chooses to 'insert gallery', the media will not appear within the post, but it is still associated with the post.
You can get all media for a post using get_children() like so;
$media = get_children(array(
'post_parent' => $post_ID,
'post_type' => 'attachment'
));
Related
Let's say I have to code the page 'Home' of this site, what should I do as a programmer? Write the content in the template and if the user needs a modification make him call me or show the content by reading a specific posts of a determined category?
For example, create a category 'slideshow' and loop through it and add as many slides as posts are or a category 'why love us' and do the same?
How senior programmers in WordPress face this?
You have create one template as you say that will be home, Now if i am a developer for this site , i will divide this i.e.
Slider => May use plugin or custom post type.
Why Love Us => May be a custom filed is this is fixed in size, or may create custom post type
Our Teachers => Will be a custom post type.
Courses => Another custom post type
Testimonial => Another Custom post type
Gallery => It is easy to use plugin or wordpress built in media gallary
Blog => Will be popular or recent post
Other general things will be a theme options
So, you can manage your back-end like this so use can easily understood and easy to modify or update content.
am using WCK plugin for Custom Post Types and Fields
Its seems nice and i have done my work fine
One of my Custom Types has a custom field for upload an mp3 file
And now i want to get all the custom posts that have value for this mp3 field.
In other situations for example get all post that have thumbnail i use
'meta_key' => '_thumbnail_id'
Is there any similar approach to get the custom posts that have the mp3 field set.
UPDATE
Searching the db i noticed that there is a child post as attachment, so maybe its not a custom field problem and maybe i need to get the post that actually have attachment
Thanks
try use 'meta_key' => 'name_your_custom_field_for_mp3' You can see ACF documentation about this
I am able to make custom post type and custom meta box but my situation is that i want to attach multiple instance of custom meta box to custom post type.
my custom post type is show which have custom fields like start date,link,venue lets call it showinfo
now for every show i can have multiple showinfo
so how to achieve that
in attached image see show events time box in right middle side of picture that better explain what i am asking
If the maximum number of instances of showinfo is small, then you could just put them all in one meta box.
If the number is large or unlimited, the you would be better off creating another custom post type like "showinfo". You could create this the same way you created your existing post type.
Then define a custom metabox (http://codex.wordpress.org/Function_Reference/add_meta_box) to each of the showinfo posts with the same information as you have in the right-hand column example in your question.
In addition, put a SELECT drop-down in the Meta Box listing all of the existing shows, and require that the person creating the showinfo pick one.
All of the information from the Meta Box gets stored as post_meta for the showinfo post. You can have as many show times (showinfo posts) as you want for a show.
When you want to display the show information for show, just use a custom query to get all of the showinfo. For example:
$args=array(
'meta_key'=>'show',
'meta_value'=> 'some show identifier',
'post_type' => 'showinfo',
'post_status' => 'publish',
'posts_per_page' => -1,
);
$my_query = new WP_Query($args);
I have developed a custom module which creates a specific content type in Drupal and allows users to add Images and some text. Now I want to add a preview section to my module for users to see the final out-put, the preview with real Images and text content while they are completing the form. I would like to know if this is possible to do Drupal and if so, what would be the best approach.
PS. I don't want to do any hacks and ruin the Drupal core.
Cheers!d
You'll probably need to make this custom and might want to consider the Drupal ajax framework for this. There's a question Adding AJAX to existing node form on DrupalStackExchange providing an answer for ajax use with the Drupal Form API.
In your custom module upon the custom code you already have, add hook_form_alter() to hook into your content type by$form_id and implement ajax on your form elements as the answer in the link describes. Then you can add a form field of type markup in which you render the form elements ajax callback output.
$form['live_preview'] = array(
'#type' => 'markup',
'#markup' => $some_ajax_rendered_output,
);
I'm working on a mass upload of images and gallery posts, so I would like to prepare my posts offline.
The gallery code is [gallery include="94,104"] where the ID numbers are assigned by WP at uploading time.
It would be a big help to modify the gallery script so media could be referred by post_title,post_name or guid, so the post content can be prepared without knowing the ID. Ideally, I would like to do: [gallery include=" IMG_4736.jpg"].
Unfortunately I haven't found a way to identify a media element by its file name.
Any help would be much appreciated.
There are two aspects to this, first you can find media elements by the title with an instance of the WP_Query class, or you can use get_posts(). Set the post type to attachment and of you go.
Secondly to use the titles as the identifiers in the shortcode you are going to need to
add_filter( 'post_gallery', 'my_function' );
This will allow you to alter the way files are selected and presented for the shortcode. See the source code for what is output ordinarily.
I must say, it seems a strange approach - the ID is the best way to uniquely identify an item (what if you get two images with the same title?). You know you can add a gallery using the 'Add Media' button and that will insert the ID's for you? - just checking :)