Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

So in template.php the original function looks like this:

    function meta_form() {
        global $wpdb;
        $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
        $keys = $wpdb->get_col( "
            SELECT meta_key
            FROM $wpdb->postmeta
            GROUP BY meta_key
            HAVING meta_key NOT LIKE '\_%'
            ORDER BY meta_key
            LIMIT $limit" );
        if ( $keys )
            natcasesort($keys);

Meanwhile someone in my office changed it to do this:

    function meta_form() {
        global $wpdb;

      if ( isset($_GET['post']) )
        $post_id = (int) $_GET['post'];
      elseif ( isset($_POST['post_ID']) )
        $post_id = (int) $_POST['post_ID'];
      else
        $post_id = 0;

      if ( $post_id ) {
        $post_ = get_post($post_id);

      }

      if ($post_->post_type == 'video_photo' ){
        $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
        $keys = $wpdb->get_col( "
            SELECT meta_key
            FROM $wpdb->postmeta
        where meta_key like 'tqmcf_%'
            GROUP BY meta_key
            HAVING meta_key NOT LIKE '\_%'
            ORDER BY meta_key
            LIMIT $limit" );
      }else{
        $limit = (int) apply_filters( 'postmeta_form_limit', 30 );
        $keys = $wpdb->get_col( "
            SELECT meta_key
            FROM $wpdb->postmeta

            GROUP BY meta_key
            HAVING meta_key NOT LIKE '\_%'
            ORDER BY meta_key
            LIMIT $limit" );
      }

        if ( $keys )
            natcasesort($keys);

I've been doing research and it looks like any changes to the core should be done in my theme's function.php file using add_filter or add_action. Is this the right way to go? How would I do that? I still don't have too good of a grasp of how they work.

Thanks for your help in advance.

share|improve this question

2 Answers 2

up vote -1 down vote accepted

Seems like you asked this Q on SO as well, I posted following answer over there:

The meta_form function is not pluggable, and there are no hooks available, so, as hacking the core is not really recommended, you'll need another approach. The following is a jQuery solution. Put the code in the functions.php file of your theme, or in a plugin:

add_action( 'admin_footer', 'so17239871_mod_metakeyselect' );
function so17239871_mod_metakeyselect()
{
    global $pagenow, $post_type;

    if( ! ( 'post.php' == $pagenow && 'video_photo' == $post_type ) )
        return;
?>
<script type="text/javascript">
jQuery(document).ready(function(){
    jQuery("#metakeyselect > option").hide();
    jQuery("#metakeyselect > option[value^='tqmcf_']").show();
});
</script>
<?php
}
share|improve this answer
    
downvoters, please explain –  diggy Jun 27 '13 at 16:38

There are no hooks (that I see) in that function that you can use to alter it in that way. However, the values that match tqmcf_% are something created by code under your control and I am pretty sure that if that data were saved with a leading underscore-- _tqmcf_% then the original unaltered function will work (which is what should have been done in the first place).

Saving that data differently would be my advice for solving this particular problem.

share|improve this answer
    
I tried looking through the whole project for tqmcf_% but could only find that one instance. Is that an actual string? or a variable? –  Edmund Jun 21 '13 at 15:48
    
The % is a MySQL LIKE query wildcard. You won't find it when the values are saved. Just look for tqmcf_. Unfortunately, the string may be generated dynamically so it may be something like $tqmcf.'_ but that is one of many, many possibilities. –  s_ha_dum Jun 21 '13 at 15:52
    
Ooo nice thanks. However, I still don't understand how _tqmcf_ differs from tqmcf and how a leading undescore would fix anything? –  Edmund Jun 21 '13 at 15:54
    
The original function searches for keys that start with an underscore. If your data has an underscore the original function will retrieve it. Hacking that function was unnecessary from where I sit. There were other ways to achieve the same thing. Once you change this, though, you will have to change other things but that is the project you are facing. –  s_ha_dum Jun 21 '13 at 15:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.