Tag Info

Hot answers tagged

4

I doubt it would justify the effort of writing custom SQL queries for only 2500 posts. Within the wp_set_object_terms( $object_id, ... ) function we have: $object_id = (int) $object_id; so it's correct that it only takes a single post id as input. So you would need to loop over your $post_ids array but it might be sufficient to use the ...


3

get_the_utm_vars doesn't work like you think it does. A function cannot return more than one value. Right now, when the first return is reached, that value is returned and none of the following lines are ever reached. You could have get_the_utm_vars return an array of values instead: function get_the_utm_vars(){ $utm = array(); $utm['source'] ...


3

Change this line setcookie( 'cookiename', 'cookievalue', time() + 3600, 'mysite.net/sites/site1/', 'mysite.net/sites/site1/'); to setcookie( 'cookiename', cookievalue, time() + 3600, COOKIEPATH, COOKIE_DOMAIN);` COOKIEPATH and COOKIE_DOMAIN are WP constants now, but the codex is not updated yet.


2

I needed to do something very similar for one of the plugins that I was developing. I registered two separate cpt's during plugin activation, and each of those cpt's should use a custom single template that I had bundled with the plugin code base. You should be able to do the same for page templates, using the page_template filter. Here is my function ...


2

I always break my functions.php up into more managable, specific functionality files, for instance, all footer related functions goes into a file called footer-functions.php and pagination functions goes into a file called pagination-functions.php. This way, my code stays organised, managable and I don't kill my functions.php. This however, is only related ...


2

Another option is: <?php echo str_replace('Brand: ','',get_the_archive_title()); ?> Replace Brand: with whatever text you are wanting to get rid of. Its worth looking into the difference between get_the_archive_title() and the_archive_title() the_archive_title() returns an array get_the_archive_title() returns a string


2

The plugin you mentioned is only reportedly tested up to WordPress version 3.6.1. I would not (in general) recommend abandoned plugins, because they might impose security risks. Additionally it uses PHP4 class constructors, that might soon be deprecated and it calls non static methods in a static way. If you remove the plugin, you should be able to use ...


2

If you define your own empty function, then it can cause a problem when the plugin tries to load its same function. The simplest way around this is to use PHP's built-in function_exists() method wrapped around the function call. If that function is defined (like inside the plugin) it'll run the call. If not, it's skips over it without a second thought. if ( ...


1

This answer will be long, but can be helpful in some way. First of all, detect why you're getting this error: Majority of the time when you see a Wordpress' White Screen of Death, it means that you exhausted the memory limit of your server settings. This could be caused by a plugin that you may be using that is not functioning properly. It could also ...


1

You could use get_attached_media() function to check if the post has any attached images to it. Also, you use wrong logic operator. Your code would look like this: $attached_images = get_attached_media('image', $post->ID); if ( (get_the_post_thumbnail() == NULL) && empty($attached_images) ) { // show your default image } else { // do nothing, I ...


1

See Wordpress Template Hierarchy and figure out which page you've to modify. From this figure, it's easy to see that if you want to modify your homepage, you have to modify frong-page.php. It it doesn't exist, check if a custom page template is used to serve the home page and edit that page template. If front-page.php doesn't exist and you are not using ...


1

Your code has a couple of flaws which I'm not going to go into detail now. Here is a short list pre_get_posts is an action On any type of archive page you need to make sure you only target the main query and the front end when using pre_get_posts Your syntax is very hard to debug and not supported by most code editors. Although if (): else : endif; is ...


1

Your problem is that you've used the get_template_directory_uri() function for your include path. As indicated by the function name, this returns a URI (not a path), which is no use for including one php file into another. Simply enter the relative path of the file to be included. E.g. if your structure is: /my-theme |--functions.php |--/lib ...


1

Normally Wordpress does not run shortcode that you put into a custom field. By default, Custom Fields display whatever value you enter, as plain-text, so if you try entering a shortcode, (in the format [shortcode] VALUE [/shortcode]) you’ll end up displaying the entire text, including the tags. Add the following in your template file, it can be single.php ...


1

Use this instead: Concatenate the html then return it. function check_my_login( $atts) { $html = '<form action="" name="" method="post" enctype="multipart/form-data">'; $html .= '<div class="form-group">'; $html .= '<label for="description">Project Description</label>'; $html .= '<textarea name="p_description" ...


1

Here is an idea but before we go into details, here are VERY VERY IMPORTANT notes NOTE: READ THIS FIRST Take a database back up before running this code. It is advisable to run this on a local install first for testing purposes. Note on wp_trash_post(), from the codex If trash is disabled, the post or page is permanently deleted. I have tested the ...


1

Since WordPress 3.6+ There is a function to print out all the media in the content. get_media_embedded_in_content();


1

The main benefit with hooks ( such as add_action ) is that they allow you to add additional logic very easily based on priority. The only way to achieve the same thing with a standalone function is to edit the function directly. You wouldn't want to do this in premium theme ( or core ) as any time there's an update your function will be overwritten. Take ...



Only top voted, non community-wiki answers of a minimum length are eligible