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
If the user logged in it display like this
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
Since custom fields are kept in the meta table, you can proabably just remove this line:
Alternatively, you can use a boolean as a parameter to not run this line of code.
HTH
OK i found the answer. Thanks to @t31os and his code.
This is what i did.
Replaced this line
with
And then again I replaced this first line
with
Voila its working perfectly now. 🙂