@@ -24,7 +24,11 @@ public static function linkPostType($permalink, $post, $leavename, $sample) {
2424 }
2525
2626 protected static function linkRewriteFields ($ permalink , $ post ) {
27- return preg_replace ('#(%field_(.*?)%)#e ' , 'CustomFieldsPermalink::linkRewriteFieldsExtract($post, " \\2") ' , $ permalink );
27+ $ replaceCallback = function ($ matches ) use (&$ post ) {
28+ return CustomFieldsPermalink::linkRewriteFieldsExtract ($ post , $ matches [2 ]);
29+ };
30+
31+ return preg_replace_callback ('#(%field_(.*?)%)# ' , $ replaceCallback , $ permalink );
2832 }
2933
3034 public static function linkRewriteFieldsExtract ($ post , $ fieldName ) {
@@ -48,16 +52,23 @@ public static function registerExtraQueryVars($value) {
4852 public static function processRequest ($ value ) {
4953 // additional parameters added to Wordpress
5054 // Main Loop query
51- $ value ['meta_key ' ] = $ value [self ::PARAM_CUSTOMFIELD_KEY ];
52-
53- // do not check field's value for this moment
54- if (true === self ::$ checkCustomFieldValue ) {
55- $ value ['meta_value ' ] = $ value [self ::PARAM_CUSTOMFIELD_VALUE ];
55+ if (array_key_exists (self ::PARAM_CUSTOMFIELD_KEY , $ value )) {
56+ $ value ['meta_key ' ] = $ value [self ::PARAM_CUSTOMFIELD_KEY ];
57+
58+ // remove temporary injected parameter
59+ unset($ value [self ::PARAM_CUSTOMFIELD_KEY ]);
60+
61+ // do not check field's value for this moment
62+ if (true === self ::$ checkCustomFieldValue ) {
63+ if (array_key_exists (self ::PARAM_CUSTOMFIELD_VALUE , $ value )) {
64+ $ value ['meta_value ' ] = $ value [self ::PARAM_CUSTOMFIELD_VALUE ];
65+
66+ // remove temporary injected parameter
67+ unset($ value [self ::PARAM_CUSTOMFIELD_VALUE ]);
68+ }
69+ }
5670 }
5771
58- // remove temporary injected parameters
59- unset($ value [self ::PARAM_CUSTOMFIELD_KEY ], $ value [self ::PARAM_CUSTOMFIELD_VALUE ]);
60-
6172 return $ value ;
6273 }
6374
0 commit comments