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.

The following code hides "the_content" output

add_filter( "the_content", "cp_module_pcontent_post_content" );
function cp_module_pcontent_post_content($content){
        global $post;
        global $cp_module_pcontent_hide;
        if(!in_array($post->ID,(array)$cp_module_pcontent_hide)){
            return $content;
        }
        $c = '<p>' . get_option('cp_module_pcontent_text_pay') . '</p>';
        $c .= apply_filters('cp_module_pcontent_post_content_'.$post->ID, '');
        $c .= '<form method="post">';
        $c .= '<input type="hidden" name="cp_module_pcontent_pay" value="'.$post->ID.'" />';
        $c .= '<p><input type="submit" value="'.get_option('cp_module_pcontent_text_button').'" /></p>';
        $c .= '</form>';
        if(!is_user_logged_in()){
            $c = get_option('cp_module_pcontent_text_logout');
        }
        $c = str_replace('%points%',cp_formatPoints(get_post_meta($post->ID,'cp_pcontent_points', 1)),$c);
        return $c;
    }

Check these screenshots.

If the user not logged in it display this

enter image description here

If the user logged in it display like this

enter image description here

Please note only the_content output is hidden

Here is my problem. I'm using magic fields plugin. It is a plugin to create custom fields.

For example this is the code my single.php file using.

    <div class="entry-content">
            <?php the_content(); ?>
    </div>

 <!-- magic fields plugin code starts -->
    <div class="custom-content">
            <?php if (function_exists('get_field')) { 
                    $requirements = get_field('requirements_requirements');
                        if($requirements){  
                            foreach($requirements as $requirement){
                            echo $requirement;
                            } 
                        } 
                    } ?>

    </div>
  <!-- magic fields plugin code ends -->

Magic fields plugin output are not hidden here
I want to hide those Magic fields plugin output instead of the_content output. I mean requirements instead of the_content.

When i replace "the_content" with "the_title" it hides the title.

For example like this

add_filter( "the_title", "cp_module_pcontent_post_content" ); //hides title

add_filter( "the_tags", "cp_module_pcontent_post_content" ); //hides tags

add_filter( "wp_list_categories", "cp_module_pcontent_post_content" ); //hides categories

add_filter( "???????", "cp_module_pcontent_post_content" ); //hides magic fields group

To hide those requirements I need to replace

add_filter( "the_content", "cp_module_pcontent_post_content" );

to

add_filter( "xxxxxxxx", "cp_module_pcontent_post_content" );

Can you tell me what is that xxxxxxxx?

Thanks

share|improve this question
    
I'm not sure you can just attach the same filter to multiple hooks, generally one hook is not the same as the next and what you're showing above is re-using the same function(which i'm surprised works). The main thing you need to know appears to be finding a suitable hook in the magic fields plugin. I don't know the plugin nor am i searching through all those files to find hooks(sorry you're on your own there). –  t31os Dec 13 '11 at 19:40
    
No i'm not using same filter to multiple hooks, I just given some examples that it worked when i replace the_content with the_title / the_tags / wp_list_categories. And one more thing my first code snippet is found in cubepoints plugin. This is the full snippet code –  Giri Dec 13 '11 at 19:50
    
@t31os How to award my 50 reputation to you? I answered myself with the help of your code –  Giri Dec 13 '11 at 20:48
add comment

2 Answers

Since custom fields are kept in the meta table, you can proabably just remove this line:

 $c = str_replace('%points%',cp_formatPoints(get_post_meta($post->ID,'cp_pcontent_points', 1)),$c);

Alternatively, you can use a boolean as a parameter to not run this line of code.

HTH

share|improve this answer
add comment
up vote 0 down vote accepted

OK i found the answer. Thanks to @t31os and his code.

This is what i did.

Replaced this line

echo $requirement;

with

echo apply_filters('requirement','$requirement');

And then again I replaced this first line

add_filter( "the_content", "cp_module_pcontent_post_content" );

with

add_filter( "requirement", "cp_module_pcontent_post_content" );

Voila its working perfectly now. :)

share|improve this answer
    
Still not quite sure what you were aiming, just happy to hear you reached a solution, and i'm happy to have helped all the same.. :) –  t31os Dec 13 '11 at 21:18
add comment

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.