Disable rwmb_meta() on Search Results
- This topic has 5 replies, 3 voices, and was last updated 9 years, 10 months ago by
Maxell.
-
AuthorPosts
-
June 17, 2015 at 1:39 AM #992
Maxell
ParticipantHi.. 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
June 17, 2015 at 3:42 PM #994Tan Nguyen
ParticipantHi 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
June 20, 2015 at 2:27 AM #1003Maxell
ParticipantHi 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 contextI 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
June 22, 2015 at 10:23 AM #1007Tan Nguyen
ParticipantHi 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 byrwmb_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.
June 23, 2015 at 8:15 AM #1011Anh Tran
KeymasterHi, 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; }
June 23, 2015 at 1:44 PM #1013Maxell
ParticipantThanks Anh, I am gonna try it tonight and get back with the results.
regards
-
AuthorPosts
- The topic ‘Disable rwmb_meta() on Search Results’ is closed to new replies.