Jump to content

Recommended Posts

I have wordpress 3.0 installed on PHP 5. I am using a custom theme that creates individual classifed ads whose fields, including custom fields, are stored in the postmeta table.  Each Post/Ad may have different custom fields associated with it because some of the ads, depending on category or sub-category, may have different custom fields stored with that post/ad.

 

There is an existing custom field function in the functions.php that pulls all the custom fields associated with that $post_id value of the ad or post called for.

 

I created a similar function that JUST pulls the custom fields that store CHECKBOX values. I created this so that I can separate the checkbox values stored in arrays in the "meta_value' fields identified by a "meta_key" named 'cp_checkbox_'variable name here'.

 

I want to modify this part of the function...with a filter

 

foreach ($results as $result) :
            // now grab all ad fields and print out the field label and value

$post_meta_val = get_post_meta($postid, $result->field_name, true);

            if (!empty($post_meta_val))
                if($result->field_name != 'cp_price')
                    echo '<li><span>' . $result->field_label . ':</span> ' . cp_make_clickable($post_meta_val) .'</li>'; // make_clickable is a WP function that auto hyperlinks urls

        endforeach;

    } else {

      echo __('No ad details found.', 'cp');

    }

 

I want to EXCLUDE rows whose "meta_key" value includes the word 'checkbox'

 

When I created another function to FOCUS on extracting just those rows whose meta_key field contained the word 'checkbox' I made this one of the sql query conditions:

 

`wp_postmeta` . `meta_key` LIKE '%%checkbox%%'

 

this works well and selects rows whose meta_key may vary in naming...such as ""  or" cp_checkboxstuff"  etc....it catches the variant names as long as they have some form of ''checkbox"

 

So, if I want one function to grab just the rows containing checkbox meta_value

 

and another function to grab just the custom fields that are NOT checkboxes

 

What is a Wordpress filter that I can apply to

$post_meta_val = get_post_meta($postid, $result->field_name, true);

that will strip out any custom field rows where the "meta_key" contains some variant of "...checkbox..."

 

I am trying to do this with the global values already present instead of building another sql query directly to the database.

 

I see all kinds of way to strip out POSTS according to tags and categories but nothing yet specifically for creating this filter on custom fields called.

 

Thanks for your help, Wordpress geeks!

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.