Support Forum
Hi.. I am having a problem, I have a lot of custom meta boxes for each pages, for instance changing header background color for individual pages, it works fine on individual pages, however when I search something and any page for example "Red Background Header", is first result on search page, the header background also become red on result result page, I want to completely disable rwmb_meta() in search results and other pages, something like
if(is_search())
disable(rwmb_meta());
no values from rwmb_meta() is overwritten... is there any way to handle this ?
regards
Hi Maxell,
Can you show me where did you put rwmb_meta
function? If you wanna show meta box value on singular pages, like Post or Page, you can put rwmb_meta to single.php, page.php or singular.php (depend on your template hierarchy).
In case both singular pages and archive pages in your theme are included same file. You can exclude rmmb_meta on search page like so:
// Only execute rwmb_meta function when current page is not search page
if ( ! is_search() )
rwmb_meta('your_value');
Regards
Tan Nguyen
Hi Tan, thanks for the reply.
The template hierarchy is very complex, I wont be able to explain here, for example it generates external CSS and has all the checks as compared to $smof_data (values from theme admin panel) and rwmb_meta values, and each bit of HTML is almost a template so I cant edit all templates to check if its included in a search result of fetched directly on page/post.
... and basically all values from $smof_data array are overwritten as compared to rwmb_meta values..
and this only happends when I search for any page and any page that has rwmb_meta values, then are overwritten and changes the search page header as well. What I want to do is somehow ignore rwmb_meta values and not overwritten on $smof_data array.
For this I can only think of 2 options (used in header.php):
1. if its a search page unset(rwmb_meta()) values, or change values of each keys rwmb_meta(EACH_KEY) = "xxx";
2. if its a search page, redefine rwmb_meta() values again, or example the SUB HEADER is set to SHOW in $smof_data['show_sub_header'] = "show" and within rwmb_meta("show_sub_header") value is "hide" so I would manually change it to:
if($smof_data['show_sub_header'] == "show")
rwmb_meta("show_sub_header") = "show";
but with second method I get error :
Fatal error: Can't use function return value in write context
I need a solution as I completely got stuck, and its almost impossible to goto each function and compare if its being within the search page or the original post/page.
regards
Hi Maxell,
That fatal error happened when you assign a value to function. You cannot do that.
For this problem, we'll need to change the logic before $smof_data
has overridden by rwmb_meta
. After that, we have no chance to do it. For example, we'll assign each $smof_data index with rwmb_meta key only if current page is not search page. You can post some lines on that file and I'll have a look at with you.
Regards.
Hi, there's a way to change the returned value of rwmb_meta
which can be useful for your case.
The filter is rwmb_meta
also and we can do like this:
add_filter( 'rwmb_meta', 'prefix_meta', 10, 4 );
function prefix_meta( $meta, $key, $args, $post_id )
{
if ( ! is_search() )
return $meta;
// If this is search page, do whatever you want with the returned value $meta
$meta = '';
return $meta;
}
Thanks Anh, I am gonna try it tonight and get back with the results.
regards