Skip to content

Commit

Permalink
Bugfix. Close #4 #5.
Browse files Browse the repository at this point in the history
  • Loading branch information
athlan committed Nov 11, 2015
1 parent 979a106 commit 9b51705
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions wordpress-custom-fields-permalink-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ public static function linkPostType($permalink, $post, $leavename, $sample) {
}

protected static function linkRewriteFields($permalink, $post) {
return preg_replace('#(%field_(.*?)%)#e', 'CustomFieldsPermalink::linkRewriteFieldsExtract($post, "\\2")', $permalink);
$replaceCallback = function($matches) use (&$post) {
return CustomFieldsPermalink::linkRewriteFieldsExtract($post, $matches[2]);
};

return preg_replace_callback('#(%field_(.*?)%)#', $replaceCallback, $permalink);
}

public static function linkRewriteFieldsExtract($post, $fieldName) {
Expand All @@ -48,16 +52,23 @@ public static function registerExtraQueryVars($value) {
public static function processRequest($value) {
// additional parameters added to Wordpress
// Main Loop query
$value['meta_key'] = $value[self::PARAM_CUSTOMFIELD_KEY];

// do not check field's value for this moment
if(true === self::$checkCustomFieldValue) {
$value['meta_value'] = $value[self::PARAM_CUSTOMFIELD_VALUE];
if(array_key_exists(self::PARAM_CUSTOMFIELD_KEY, $value)) {
$value['meta_key'] = $value[self::PARAM_CUSTOMFIELD_KEY];

// remove temporary injected parameter
unset($value[self::PARAM_CUSTOMFIELD_KEY]);

// do not check field's value for this moment
if(true === self::$checkCustomFieldValue) {
if(array_key_exists(self::PARAM_CUSTOMFIELD_VALUE, $value)) {
$value['meta_value'] = $value[self::PARAM_CUSTOMFIELD_VALUE];

// remove temporary injected parameter
unset($value[self::PARAM_CUSTOMFIELD_VALUE]);
}
}
}

// remove temporary injected parameters
unset($value[self::PARAM_CUSTOMFIELD_KEY], $value[self::PARAM_CUSTOMFIELD_VALUE]);

return $value;
}

Expand Down

0 comments on commit 9b51705

Please sign in to comment.