New answers tagged

0

I found this. /** * @snippet Disable Link to Products @ Loop * @how-to Watch tutorial @ http://businessbloomer.com/?p=19055 * @sourcecode http://businessbloomer.com/?p=19916 * @author Rodolfo Melogli * @testedwith WooCommerce 2.5.2 */ // Close </a> tag just after it opens before product item add_action( '...


0

OK - so, first, you don't need to serialize/unserialize. get_user_meta() will return an array, and delete_user_meta() can remove a specific value. So, simplifying a few other things here and below, your remove function would work like this (very simple): function teo_bookmark_remove() { $postID = $_POST['post_id']; $current_user = ...


0

I wasn't able to get get_sites working, so here is a solution using wp_get_sites until further documentation is released on the new version. wp_get_sites returns a lot of data about the subsite, including creation and last modified dates. I turned my original $stageurl array into a multidimensional array and added registration date as a value. The ...


0

You can add more than one filter call, so each of your custom meta_key's can be handled in separate code and when executed will cumulatively adjust the query. Perhaps look at the pre_get_posts filter rather than parse_query (although the solution I'm suggesting could possibly work in either case). pre_get_posts gives you access to the current query before ...


1

Using get_sites() in WP 4.6+ It looks like wp_get_sites() will be deprecated in WP 4.6. The new replacement is: function get_sites( $args = array() ) { $query = new WP_Site_Query(); return $query->query( $args ); } Very similar to get_posts() and WP_Query. It supports various useful parameters and filters. Here's what the inline ...


1

First, I would use WP_Query instead of the manual DB query (and don't tell me that's because of performance because you're querying 2 times the same thing). Second, you're saving your post as draft status and querying post with status publish


0

You need to add the paged parameter to your WPQuery: $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; $query = new WP_Query( array( 'posts_per_page' => 5, 'paged' => $paged ) ); Here are the docs.


-2

<?php //simple wordpress loop $loop= new WP_Query( array( 'post_type'=>'post', 'orderby'=>'ID', ) ); if($loop->have_posts()): while($loop->have_posts()): $loop->the_post(); ?> //all the stuffs you want to put in <a href="<?php the_permalink(); ?>"><h2>...


-2

Use get_posts with posts_per_page => 1 to get only one latest result. You can than use get_permalink() to get the permalink. $args = array( 'posts_per_page' => 1, 'orderby' => 'date', 'order' => 'DESC', ) ; $latest_posts = get_posts($args); $permalink = get_permalink($latest_posts[0]->ID);


0

Default wordpress galleries img tags close with invalid XHTML That's not the case, as far as I understand it. The native gallery uses wp_get_attachment_image() to generate each image tag and wp_get_attachment_link(), that's a wrapper for wp_get_attachment_image(), to fetch the image link. The output of wp_get_attachment_image() is: $html = rtrim("<...


1

If you just want to add a string it would be: $city = "Re: " . get_comment_meta( get_comment_ID(), 'city', true );


1

As linked to from the comments on your question, the post_gallery filter should help you here. Unlike a lot of other hooks though, you can't filter the output that comes through from WordPress; you can only provide your own alternative output. This is slightly annoying, and results in you needing to build the gallery from scratch. You can do that with a bit ...


0

The absolute best way to migrate is: get access to your mysql server make a dump of the database get access to your file server zip your /wp-content folder upload your zip and sql files to the new server uncompress the /wp-content file load the old dump into your new database server modify your wp-config.php and point to the new database server source: ...


0

@bravokeyl is the probably the best answer to your immediate problem. But to address the following: Is there a way to hook into an action or filter and remove ALL the update nag messages for non-admin users? No. Nag messages in WordPress are just a callback to added to the admin_notices hook which print some HTML to the page. They are practically ...


5

In wp-admin/includes/update.php file if ( current_user_can('update_core') ) $msg = sprintf( __('An automated WordPress update has failed to complete - <a href="%s">please attempt the update again now</a>.'), 'update-core.php' ); else $msg = __('An automated WordPress update has failed to complete! Please notify the site ...


-1

wp_send_json( $result ); if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { wp_die(); } UPD The besat way to use ajax requests with wp is to use wp native ajax actions add_action( 'wp_ajax_my_action', 'my_action_callback' ); add_action( 'wp_ajax_nopriv_my_action', 'my_action_callback' ); https://codex.wordpress.org/AJAX_in_Plugins so you ...


-1

Try using the plugin called Duplicator https://wordpress.org/plugins/duplicator/ I always it to migrate website. You should not face any problems with this one As for the errors you are facing there might be additional files that blue host might keep. Do check for any unwanted files or folders


1

You need to turn WP_DEBUG on in your wp-config.php: define( 'WP_DEBUG', true ); That'll help a lot with working out where that 500 error is coming from. Based on the PHP versions you've mentioned, I'm 99.999% sure that the error is due to a feature that isn't available in PHP 5.2.17. You're probably looking at either shorthand array notation (eg. $array = ...


1

I tried another solution and that did the trick. I found in the WooCommerce docs this little snippet: // Display 24 products per page. Goes in functions.php add_filter( 'loop_shop_per_page', create_function( '$cols', 'return 24;' ), 20 );. It is overriding the settings in the customizer. I only have to change the number '24' to my liking.


0

You can wrap your plugin in a check to see if WooCommerce is installed and active or not : if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { echo 'WooCommerce is active.'; } else { echo 'WooCommerce is not Active.'; }


2

How can i return a PHP value from a WordPress page to a JQuery function? Use wp_localize_script to create an object and pass it to the JavaScript.


0

I don't know what hook Woocommerce uses to add that customizer code, but in your functions.php you'll have to hook your own function on a later time, like this (the last number is the lower priority): add_action ('the_name_of_that_hook','wpse_280836_mycontrol', 99) Now in the function you are hooking, you must first remove the existing control and the add ...


4

The Codex says: It's important to note that most WordPress functions properly prepare the data for output, and you don't need to escape again. For example the_permalink() already escapes the output with: echo esc_url( apply_filters( 'the_permalink', get_permalink( $post ), $post ) ); so you don't need to do that yourself here. But the ...


0

You got javascript file and CSS file! Then you have to put those files in you child theme folder like themes -> your_child_theme_folder -> js(if you dont have js folder then create one) and place your js file here AND you have to put you css file in css folder inside your child theme. Now you need to call js file from functions.php If you dont ...


1

You can use the user_register hook to capture user information after their details are saved to the database.


0

I don't know any other way There is a much, much better way to do this - custom fields. As per these instructions in the custom fields docs, let's say you use the field name iframe_url: <iframe src="<?php echo esc_url( get_post_meta( $post->ID, 'iframe_url', true ) ?>" width="960" height="540" frameborder="0" allowfullscreen="...


9

Each of the files you have mentioned are theme files. When you upgrade WordPress itself, it will not touch any themes (or plugins) you have installed, whether or not you have modified them. If this was a theme you created yourself, then you have no worries at all. However, if this was a theme created by someone else, for example a WordPress default theme, ...


0

You need to "include" the WordPress functions which then will convert your shortcode from [mycode] to the code you expect. You do this by including wp-blog-header and setting wp_use_themes to false, this then stops the header.php of the theme from being added. define('WP_USE_THEMES', false); require ('./wp-blog-header.php'); You will need to change the ...


1

Technically, they are for only one purpose: override memory_limit value in php.ini. The difference is: WP_MEMORY_LIMIT will permanently override memory_limit if its value is greater than the current value in php.ini. WP_MAX_MEMORY_LIMIT will temporarily override memory_limit with whatever value you defined. And it only happens in some events such as ...


0

Max is used on the admin side, WP_MEMORY_LIMIT is used on the front end. Don't increase the memory available more than you need to or you'll run the risk of running out of RAM if you have too many simultaneous hits on pages.


0

I solved the problem by installing php-ssh2, which removes libssh2-php on the install. $ sudo apt-get install php-ssh2 I also had to change permissions on the wp-content folder to 775, but it worked leaving the wp-content/plugins at 755. $ chmod 775 wp-content


2

I was having a similar problem with getting ssh to work after the php 7.0 upgrade. I went through the steps of this tutorial and got it working. I also had to chmod 775 the wp-content directory. However, the wp-content/plugins direcotry at chmod 755 works.


-1

// This won't show date in all cases the_date( 'F d, Y' ); // This will show date in all cases the_time( 'F d, Y' );


0

Try using Autoptimize WordPress plugin or W3 Total Cache WordPress plugin, with W3 Total cache enable minify option. They both support combining and minifying all enqueued Scripts (JS) and Stylesheet (CSS)


0

You shouldn't need to change anything in the database. If you've set up your child theme correctly, and it appears in the list of installed themes, activating that child theme, should make any updates necessary. The customizations you made back in the day should go in the child functions.php and child style.css. As long as the function names and class names ...


3

I think it's impossible to give a definitive answer here, because choiches like this are personal preference. Consider that what follows is my approach, and I have no presumption it is the right one. What I can say for sure is that you should avoid your third option: Just return null/false This is bad under different aspect: return type ...


0

You don't need php at all to achieve what you are after. This can be done with just css. This shows the title and excerpt by default. .wrap .wp-tiles-byline-fade-in .wp-tiles-tile-with-image .wp-tiles-byline { opacity: 1; } This hides the excerpt again now that we have revealed it. .wrap .wp-tiles-byline-fade-in .wp-tiles-tile-with-image .wp-tiles-...


0

Turns out what I needed is to use "in_category" NOT "is_category". Here is the solution: <?php if (in_category(7)) { echo 'yes'; } else { echo 'no'; } ?>


1

nopaging=true override posts_per_page and sets it to -1 which will return all posts. Remove that and you should be fine


0

You don't need javascript, just change the class using the get_theme_mod variable e.g. <?php $layout = get_theme_mod('embee_layout_section_options[site_layout]', '3'); $class = ''; if($layout == '1') { $class = 'this'; } elseif($layout == '2') { $class = 'that'; } ?> <div class="<?php echo $class; ?>"> // stuff </div> Put that ...


0

You capability type is not valid. I would remove the code below if you can. WordPress auto generates the capability_type. "capability_type" => array( strtolower($s), strtolower($m) ), Check out the documentation for capability_type. https://codex.wordpress.org/Function_Reference/register_post_type


0

Alternate Method The author of Metaslider suggests using WP Mobile Detect. Here is a sample of code I used to achieve a similar result to what I think you are looking for. Requires the WP Mobile Detect plugin. <?php if(shortcode_exists('metaslider') && function_exists(wpmd_is_notphone) && wpmd_is_notphone()): echo(...


-1

Have you enabled debugging in wordpress? Open wp-config.php in the root wordpress folder and change this line: define('WP_DEBUG', false); to define('WP_DEBUG', true); Your PHP errors will then output to the screen.


2

<?php /* Plugin Name: Custom output Description: A module to test the custom output. To test: http://your_wordpress_site.com/customop_uri_path Version: 1.0 Author: Danilo Silva Author URI: http://danilocgsilva.me */ // Write a new permalink entry on code activation register_activation_hook( __FILE__, 'customop_activation' ); function customop_activation()...


0

I am not completely sure what you mean, but it looks like you are looking for is_user_logged_in. You can use this test in your templates to test if a user is logged in and display information accordingly. In this fassion: if (is_user_logged_in()) { ... show some content ... } else { echo "Please, login first"; wp_login_form ($args); ...


0

A dev version clearly needs to be created. Resolving this will take time. You will need debug and the ability to experiment with disabling plugins. Chances are, the slowness is caused from a bad query with a plugin. Or too many scripts. Also, 100mb of memory is far inadequate for a site with that much traffic. For me, Id go minimum 500, depending on what ...


0

Loading almost any (if not all) WordPress files directly will give nothing more than a white screen of death if you have your error reporting set properly. This is because it will trigger a fatal PHP error stopping the execution, and the correct public settings for error display is to not show them. However, if you are trying to mask that you are using ...


0

I am proud to announce that I have found the solution thanks to @cjbj good advice. I paste the code here. I know it will help others. In addition, I used the function preg_quote to protect the path to the image. protected_path = preg_quote($filename); This code works great. // $filename should be the path to a file in the upload directory. $...


5

Does it need it? Probably not (other than this edge case, props @bravokeyl). Should you add it? In my opinion, yes: From a coding/architecture POV, you're declaring "this file needs WordPress". Any direct hit to one of your theme's files (curious users, bots, "script kiddies" etc.) has the potential to leak a little bit of info (most likely filesystem) and/...


2

No, functions.php would generate PHP fatals if loaded directly as it uses the WordPress API. If functions.php tried to bootstrap and load WordPress however, then yes, it would be necessary, but if you've done that then something has gone horribly wrong and you need to start from scratch



Top 50 recent answers are included