I figured it out!!!
So I wanted to hide a specific custom field that was being called in my sidebar on password protected pages. That way the info is hidden until users entered the password. By default, when you password protect a page or post, only the content of the main section is hidden. Here’s how I got around that…
First, password protect your page.
Next, instead of using a widget to call a custom field value, use a query. For me, I have the content at the top of my sidebar. If you have it elsewhere, this solution probably won’t work for you. I edited my sidebar template and placed the query above the section that is there for widgets.
To query a specific custom field, the code is as follows:
<?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, 'custom-field-name', true);
wp_reset_query();
?>
To hide other content until a page’s or post’s password is entered, the code is as follows:
<?php
if ( !post_password_required() ) {
echo 'protected stuff';
}
?>
To get what I wanted to achieve, I simply combined the two codes to get the following result for my sidebar template. And it works!
<div id="sidebar">
<?php
global $wp_query;
$postid = $wp_query->post->ID;
if ( !post_password_required() ) {
echo get_post_meta($postid, 'progress', true);}
wp_reset_query();
?>
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Default-Sidebar") ) : ?>
<?php endif; ?>
</div>
<!-- sidebar END here -->
Hope this helps anyone else looking to get the same or similar result!