vancoder
  • Member for 9 years
  • Last seen this week
  • British Columbia
Loop increase in while loop not working
Accepted answer
1 votes

You're reassigning 1 to $i on every loop: if ( $i = 1) { This should be if ( $i == 1) { or even if ( $i === 1) { which will also compare the post type, which is best practice. In PHP, = is ...

View answer
Incomplete term slugs output from a foreach loop with get_the_terms
-1 votes

You are overwriting $product_cat_slugs on every iteration of your loop - so when it's finished, that variable will be set to the last value. Why not do all of your outputs inside that loop? Or if for ...

View answer
How to create multiple users at once?
2 votes

It's possible if you have access to WP CLI: wp user import-csv https://developer.wordpress.org/cli/commands/user/import-csv/

View answer
Conditional Generation of Image Sizes using add_image_size
Accepted answer
1 votes

Take a look at the intermediate_image_sizes_advanced filter. This filter receives the attachment ID in question, so with that you should be able to work out whether or not you want the intermediate ...

View answer
How exclude or skip post type with get_next_post_link
1 votes

What is Status? If it's a taxonomy - and, by the look of it, it should be - you can exclude any given term in get_previous_post_link using the $excluded_terms parameter. If status is not a taxonomy ...

View answer
Which meta_query and post_content blend is better in WP_Query, performance wise?
1 votes

Why would you need tag__in for option 2? You're not searching for multiple values, only your 1 or 0. In which case, options 2 and 3 amount to the same thing behind the scenes: a taxonomy query. This ...

View answer
Relationship between set rewrite flag in register_post_type and add_rewrite_rule
2 votes

That's not what the rewrite argument of register_post_type means. If you set it to false, that doesn't mean "prevent any rewriting of this post type's URL, ever." That wouldn't even be ...

View answer
hide elements of admin with css file
Accepted answer
1 votes

It's always better to encapsulate your styles in a separate file, so your first example is closer. That said, the documentation for admin_print_styles says quite clearly: admin_print_styles should ...

View answer
Order by post_date does not work in Previous and Next post pagination
Accepted answer
0 votes

$excluded_terms should be the 2nd arg to get_previous_post etc, not the first. Also those filters should not be required.

View answer
How do I modify the custom footer text and get theme version number to show in wordpress admin?
Accepted answer
2 votes

Try returning your span instead of echoing it. function modify_admin_footer() { return '<span id="footer-thankyou">Developed by <a href="http://www.toolcart.com" ...

View answer
Looking for a better way to initiate cron job
Accepted answer
1 votes

Simply check if the event is scheduled, and if not, schedule it: add_action( 'init', function () { if ( ! wp_next_scheduled( 'my_scheduled_event' ) ) { wp_schedule_event( ...

View answer
Allow a user or role to view drafts and previews, but not other admin privileges?
0 votes

One way to allow a normally excluded role to access previews is to harness the posts_results hook, in conjunction with an is_preview condition. Here's an example for the contributor role. function ...

View answer
Facebook share image wrong on post not on debugger
2 votes

The problem is that your HTML is malformed. You have span tags in the head. Facebook's debugger sees this, and assumes the head must have ended and the body started, and it didn't find any og tags so ...

View answer
Why is save_post hook being called twice despite all my efforts?
2 votes

save_post becomes unwieldy under Gutenberg, in my experience. It fires at least twice, and none of the checks you have in place will distinguish between instances. I would consider replacing it with ...

View answer
Compare two meta key values against each other inside the get_posts array?
Accepted answer
2 votes

You can't do this in the meta query I'm afraid. You'd need to get all the relevant records in meta query, then make that comparison inside PHP, to filter out the records you don't need.

View answer
Random item on Custom Query working Local but not on live
0 votes

My guess is that your results are cached on the production environment. Try bypassing cache by adding this to your query args: 'cache_results' => false, See https://developer.wordpress.org/...

View answer
Having Issue on Ordering CPT by Custom Field In Custom WP Query
Accepted answer
1 votes

Your query args are not quite correct. When you want to order by a custom field, you need to specify a meta_key argument, and set your orderby to the kind of ordering you need. For example: $args = ...

View answer
How can I remove the Wordpress-Version (?ver=5.x) from my plugin
3 votes

As defined in the codex, If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added. You're currently ...

View answer
Change Wordpress default registration error text [Error: This username is invalid because it uses illegal characters. Please enter a valid username.]
0 votes

Unfortunately you cannot change it, as it is hard-coded and unfiltered in core. See https://github.com/WordPress/WordPress/blob/master/wp-admin/includes/user.php#L185

View answer
How to install Bootstrap in a WordPress child theme
Accepted answer
1 votes

get_template_directory_uri() always points to the parent theme. To get the child theme use get_stylesheet_directory_uri().

View answer
user metadata in json format, update the data partly only
0 votes

You cannot use update_user_meta on its own here. You would need to get_user_meta first, decode your json into an array, update the last_seen element of the array, re-encode it and only then ...

View answer
Create a customizable child theme
3 votes

Firstly, I would ensure that your child theme is well equipped with hooks to accommodate the potential customizations. Secondly, I'd create a site-specific plugin - specific, that is, to the site to ...

View answer
Set WordPress Transient Expiration via Variable Value
1 votes

HOUR_IN_SECONDS is a WordPress constant - you cannot put a constant inside a variable and expect PHP to know it's a constant and not a string when it is parsed. In your example code, I'd just simplify ...

View answer
Login cookies blocked after customizing hashing method
Accepted answer
0 votes

This line (at least) is being output before the cookie can be set: echo '<h2>'.$hash.'</h2>'; Sending output to the screen (even empty lines) will prevent cookies being set. From the PHP ...

View answer
WP_Debug not displaying anything
Accepted answer
2 votes

The constant to output errors to screen is actually define( 'WP_DEBUG_DISPLAY', true ); WP_DEBUG_LOG would generate a debug.log in your wp-content directory, not in your site root.

View answer
Strange behavior: random HTTP error 500 fixed by visiting Permalinks settings page (htaccess issue with language code)
Accepted answer
1 votes

Looks like it might be your WPML. See here: https://wpml.org/forums/topic/wpml-add-rewritebase-en-in-htaccess/ For posterity, the summary of this page is as follows: Problem: Some wrong settings ...

View answer
Update variable value via add_filter
1 votes

Filters only allow you to directly modify the first value passed to them. In your case, that's null. If you shifted view_slug up a place, it would be available to filters using your events_view_html ...

View answer
What structure should post_content have in the database?
Accepted answer
1 votes

Those comments have been added by the Gutenberg block editor. If you remove them you'll no longer be able to edit those blocks in the admin using Gutenberg.

View answer
Creating query to show which editor (classic or block) was last used to edit a post/page
1 votes

Can you not just go by date? Assuming you made a clean switch from classic to Gutenberg? Otherwise, there's no definitive meta value, but you could just check the post content for common Gutenberg ...

View answer
Display latest posts from a specific categories
0 votes

The short answer is that the value for category should be an array of IDs. The longer answer is that it is rarely appropriate to use query_posts at all.

View answer
1
2 3 4 5
10