my goal is to list all checked attachments(images) in random order on home page with link to parent post.
I put this in attachments.php:
<br /> 'home' => stripslashes( $data['home'] ),<br />
in array_push( $post_attachments, array… and this in $attachment_details = array :
<br /> 'home' => str_replace( '"', '"', $_POST['attachment_home_' . $i] ),<br />
And this for control in admin.
<br /> <input type="checkbox" id="attachment_home_<?php echo $attachment_index; ?>" default="0" name="attachment_home_<?php echo $attachment_index; ?>" value="1" <?php if ( 1 == $attachment['home'] ) echo 'checked="checked"'; ?> /><br /> <label for="attachment_home_<?php echo $attachment_index; ?>"><?php _e("Home", "attachments")?></label><br />
Everything above work in admin, checked boxes stay checked, it write value “1” in database if checked for ‘home’.
My problem is to list all attachments with value “1” on homepage with link parent post.
I try with get_posts() , but everything works good for all attachments but I cant figure out how to filter attachments with “_attachments” meta key value ‘home’ = 1
I understand that ‘home’ value is serialized in “_attachments” but how to unserialize and use that value is where I fail.
Can anyone help me with that please?
I have manage to list attachments on home page as I wanted with little modified copy of attachments_get_attachments function , but now I get all attachments with checked new value HOME in some order.
My goal is to list only 25 attachments with value HOME in random order, so every time visitor refresh page gets different attachments.
- The topic ‘Show all checked attachments on home page’ is closed to new replies.