Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom functions should not be defined in template files #1

Closed
pnikolov opened this issue Feb 2, 2023 · 1 comment
Closed

Custom functions should not be defined in template files #1

pnikolov opened this issue Feb 2, 2023 · 1 comment

Comments

@pnikolov
Copy link

pnikolov commented Feb 2, 2023

CarBlogTheme/archive.php

Lines 67 to 97 in 29593b1

/**
*
* @param string $taxonomy - the name of the taxonomy to be filtered
* @param string $slug
*/
function compose_url(string $taxonomy, string $slug)
{
$slug = esc_attr($slug);
$url = "?{$taxonomy}[]=" . esc_attr($slug);
foreach (get_request_params() as $get_by => $args)
{
// allows selection of both: several or one (brand/engines)
//
if (in_array($slug, $args))
{
continue;
}
foreach ($args as $arg)
{
if ($arg == $slug)
{
continue;
}
$url .= "&{$get_by}[]=" . esc_attr($arg);
}
}
echo $url;
}

The compose_url() function should not be defined in the archive.php file - all the template files defined in the WordPress Template Hierarchy should be used only for templating purposes.

Also, can you clarify the double filtering of the $args for $slug and the actual conditions, they seem reversed.

@AleksandarDzh
Copy link
Owner

The double filtering was pointless because it was basically the same. It's most likely something I forgot to remove. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants