0
votes

There is a way to get all the checked checkboxes of a custom field in Magento/Wordpress(with Fishpig extension):

$post->getCustomField($customfield)

I'm trying to filter the posts by selected checkboxes, and I'm considering to compare the filters to the posts via for loop, but is there a more efficient way of filtering posts?

2

2 Answers

1
votes

You can create a custom collection of posts that are filtered by a custom field:

$posts = Mage::getResourceModel('wordpress/post_collection')
    ->addIsViewableFilter()
    ->addMetaFieldToFilter('custom_field_name', 'custom field value')
    ->load();

This will return all published posts that have the value 'custom field value' for the custom field called 'custom_field_name'.

Once you have a post model, the correct way to retrieve a custom field value is with the following:

$customFieldValue = $posts->getMetaValue('custom_field_name');
0
votes
$posts = Mage::getResourceModel('wordpress/post_collection')
    ->addIsViewableFilter()
    ->load();

foreach($posts as $post) {
    echo $post->getId() . '<br/>';
    echo $post->getPostTitle() . '<br/>';
    echo $post->getMetaValue('your_custom_field_name') . '<br/><br/>';
}

This code gets all posts and displays the post ID, post title and the value for the custom field that has the bame of 'your_custom_field_name'