Tag Info

New answers tagged

0

The below is starting after you do your query: $slide_list = array(); if ( $slides->have_posts() ) { while ( $slides->have_posts() ) { Grab the next slide using next_post to grab it without stomping globals $slide = $slides->next_post(); $slide_id = $slide->ID; Your image title is your post title: $slide_title ...


3

I think instead of using PHP rand you're better off limiting ( if you need to ) using posts_per_page and then getting a random set using orderby => 'rand'. Full List of Ordering Parameters So if I were to edit your query it would look like this: $args = array( 'post_type' => 'attachment', 'meta_key' => 'on_front_page', 'meta_value' ...


0

You need only to save generated file in the upload folder!... Use php. If you need to add this file in Media libary than use wp_insert_attachment()


1

Looking at the WP_Style class, we find the style_loader_tag filter, that might be useful. Try for example: add_filter( 'style_loader_tag', function( $link, $handle ) { if( 'google-fonts' === $handle ) { $link = str_replace( '/>', ' data-noprefix />', $link ); } return $link; }, 10, 2 );


3

You have two calls to wp_nav_menu function <?php if( has_nav_menu( 'primary-menu' ) ) { wp_nav_menu( $menuParameters = array( 'theme_location' => 'primary-menu', 'container' => '', 'container_class' => false, 'container_id' => false, 'menu' => 'Primary', 'menu_id' ...


1

While technically off topic, I think this is something that a good number ueses will enquire about, particularly those that are new to both WordPress and PHP. As suggested in the comments to your question, you can use a modulus operator to check this, and hopefully this answer will solve your problem. <?php $count = 0; /* Start the Loop */ while ( ...


0

Thanks for the answer but this doesn't display my values ! First i tryed to just set $options to global like you said, but it changed nothing and i still can't get the values : <p><?php global $options; echo $options['txt_number']; ?></p><p><?php global $options; echo $options['txt_mail']; ?></p> Also tryed to put ...


1

So I made it happen :-) There is one thing that I didn't really like to do but for the time being there is no alternative: The CronJob from the server This PHP script runs in a single (no template) file: $xmlData = file_get_contents(get_bloginfo('template_directory').'/import/external_db.xml'); // read XML data string $xml = ...


1

To be honest I think this question is off topic, because its topic is so a general concept that can apply to any language capable to handle web development. So is even broader than a general PHP question. By the way, what I want to suggest is too much for a comment. When you need to check data coming from trusted users (assuming you already have a way to ...


1

Simply use set_url_scheme() function. $share_image_src = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large' ); $share_image_src = set_url_scheme( $share_image_src, 'http' );


0

Old question but, I wanted to post this here for reference, since I never accepted an answer. This functionality is now easily achieved using the Jetpack centralized dashboard. You can administer updates to all your connected WP sites. http://jetpack.me/2014/12/16/jetpack-3-3-a-single-home-for-all-your-wordpress-sites/


0

This may be a little overkill for you needs, but I use a bulked up version of this to great effect on my site. This script will - Check what state the first_option_required option shold be in on page load (and set) Change the state of the first_option_required button upon changes to the first_option_show option. This is managed via an event hadler that ...


-1

Solved: I entered the code outside of the ajax call, in function my_footer() {


-3

**The default syntax for showposts is-** <?php $query = new WP_Query (array( 'showposts' => 5, ) ); while ($query->have_posts()): $query->the_post(); ?> <li> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> ...


0

The state of checkbox you can know only with JavaScript. In jQuery it could be look like this: if($("input[name=first_option_show]").not(":checked")){ $("input[name=first_option_required]").attr("disabled",true); }


0

You can also try to check plugin is Active or Not $PluginList = get_option('active_plugins'); $Plugin = 'PLUGIN_DIR/FILE_NAME.php'; if ( in_array( $Plugin , $PluginList ) ) { // Plugin 'mg-post-contributors' is Active } Also try below code for simplicity if ( is_plugin_active( 'PLUGIN_DIR/FILE_NAME.php' ) ) { //plugin is activated }


0

i use pre_get_posts. example: add_action('pre_get_posts','search_filterr');function search_filterr($query) { if ( !is_admin() && $query->is_main_query() ) { if ( $query->is_search ) { //$query->is_category or etc...except is_page() $arrs[]='post'; $arrs[]='page'; $arrs[]='my_carss'; ...


1

Your string example is wrong. You´re ending the echo statement right after opening the <div>. It should look like this: echo '<div class="quarter"><img src="' .$image[0]. '" alt="Logo"></div>';


-1

Make the $options variable global by changing the header_add_content() function to the following: function header_add_content() { global $options; $options = get_option('header_options'); } add_filter("the_content", "header_add_content"); Then declare $options as the global $options on the front-end template before you use it, for example: ...


0

function my_Categ_tree($catId, $depth){ $depth .= '-'; $output =''; $args = 'hierarchical=1&taxonomy=category&hide_empty=0&parent='; $categories = get_categories($args . $catId); if(count($categories)>0){ foreach ($categories as $category) { $selected = ($cat->term_id=="22") ? " selected": ""; ...


0

you can use post_status. post_status A comma-separated list of post status types that should be included. For example, 'publish,private'. possible values are: (publish|inherit|pending|private|future|draft|trash) or you can also play with: include Only include certain Pages in the list generated by wp_list_pages. This parameter takes a comma-separated ...


0

In your regex there is a space before the # $mh_regex = "/\ #[a-zA-Z0-9-]+/"; so it would match # tag instead of #tag. It might be a good idea to test your regex using this online tool: http://www.regexr.com/ it's really usefull for testing


0

You are overthinking this. The namespace structure applies at the level of individual package. There is no need or push to treat the whole site as such package. Also one of the benefits of using autoload in first place is that it makes location of classes in file system largely irrelevant. So the simple and practical approach is to: Handle namespaces at ...


1

What else can I do to the query to do as little work as possible to eliminate "extra" posts in PHP that get queried because my query is too broad. The trouble is, meta queries are slow. Metadata is a simple key => value type database. Keys are indexed, and values are longtext. That's it. No datatypes. No additional indexes. Nothing. And not to mention ...


-1

I faced this frustrating problem. None of the core functions were working. So I included this: require( '../../../wp-load.php' ); As a better practice: if(!defined(ABSPATH)){ $parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] ); var_dump($parse_uri); $parse_uri = str_ireplace('index.php', 'wp-load.php', $parse_uri); ...


1

You are using array_push() incorrectly. Do this: $classes[] = 'new-class'; Or this: array_push( $classes, 'new-class' ); But not: $classes[] = array_push( $classes, 'new-class' );


0

<script type="text/javascript"> function addText() { var input = document.getElementById('comment'); input.value = 'lots of new text ' + input.value; } </script> <p class="comment-form-comment"> <label for="comment">Comment</label> <textarea id="comment" name="comment" cols="45" rows="8" ...


0

WordPress has a WP-Cron mechanism for running scheduled tasks. It is used internally for update checks and other tasks, as well as extensively by plugins. Pro/con break down is pretty much: Does not rely or require anything from server configuration Is triggered by visits to the site, so might not fire reliably on time


1

I setup something similar. Using IIS - look into writing a .bat file which fires off a php shell script to do whatever it is you need to accomplish. once you have that bat file working, setup a "scheduled task" in IIS http://technet.microsoft.com/en-us/library/cc721871.aspx if you are on a linux system, then use crontab ...


0

try this code: if( get_theme_mod('your_setting_name') ){ //your code }else{ //your code } Note: get_theme_mod() return false if no value exist for your setting


1

if you want to show only 2, put it as a value, like so: 'posts_per_page' => 2 For the newest posts, you need to change the sort using the order and orderby params: 'orderby' => 'date', 'order' => 'ASC' Details about orderby params here: http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters Also, you should avoid ...


0

so i removed the pagination by removing this from lower <?php get_template_part('inc/pagination'); ?> <?php else: ?> <h3><?php echo ot_get_option('no_artists'); ?></h3> then changed $ppp_artists = ot_get_option('ppp_artists'); to $ppp_artists = 2; which changed the number of posts to 2 however I need ...


0

To see the menu, you need to set it up in the wordpress admin side. Go to Appearance -> Menus You should see a "Manage Locations" tab. Select it. You should see your "Main Menu" location. Choose the menu that you created there. Select Save Changes. Since you used "theme-location" to set up drawing it, you need to set a menu to your theme location to ...


0

If you use do_action( 'woo_collections_menu' ); in the template, then your function must echo its value. Otherwise, you are returning the data into a black hole, nothing is outputting what you're returning. If you use a filter, then you should return the value. The point of a filter is to take a value, filter that value through a function, then do something ...


1

You can try the comment_text filter: /** * Prepend text to each comment content. */ add_filter( 'comment_text', function( $comment_text ) { $text = 'Some text'; return $text . $comment_text; }); if you're displaying the comment text with: <?php comment_text(); ?>


0

I still couldn't figure out how to return $woo_menu; with my first example code, but I realized things don't break if I keep the rest of the structure as far as the variable goes and just echo once at the very end. This seems to work for me. Whether this is good practice or not, leave me a comment, but for now, this is the solution I'm using. Thanks. ...


0

First, year is already a WordPress query var used for date-based archives, you should change that to something unique to prevent possible conflicts. To use your own query vars within rewrite rules, you need to add them to the list of known vars: function wpd_query_vars( $qvars ) { $qvars[] = 'my_year'; $qvars[] = 'make'; $qvars[] = 'model'; return ...


1

From my understanding of actions (as opposed to filters), an action simply does something and stops processing. No return value is actually made use of. You might change your code to be a filter by accepting an argument (say the html to append to) and then make a call like the following where you want to grab the code: $html_block = ...


0

I've got it fixed: I needed to add the wp-load file that contains all the WP-functions include('../../../../../wp-load.php'); global $post; $id = $_GET['id']; $content_post = get_post($id); $content = $content_post->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]&gt;', $content); Now the content ...


0

As said, you should enqueue your style sheets like this in your functions.php in your theme: function adds_to_the_head() { // Our own unique function called adds_to_the_head wp_register_style( 'custom-style-css', get_stylesheet_directory_uri() . '/css/styles.css','','', 'screen' ); // Register style.css wp_enqueue_style( 'custom-style-css' ); // Enqueue ...


0

Try like this <script src="<?php echo get_template_directory_uri(); ?>/js/jquery.min.js"></script> But it is a good practice to en queue your script in function.php Function Reference/wp enqueue script


1

The problem was the max memory limit. I had defined in config.php define('WP_MEMORY_LIMIT', '512M'); But this was not working for me. But then I see , I need to define this define( 'WP_MAX_MEMORY_LIMIT' , '512M' ); also in config.php. Now custom property type is working for me. Now I can edit this post type.


1

You should take a look at wp_mail on the codex. This will do everything you need, and it's "the wordpress way". There are also particular controls for attachments. Basic usage is: <?php wp_mail( $to, $subject, $message, $headers, $attachments ); ?>


3

I'm surprised it's all that slow but you can remove all but one of the database calls & most of the looping by passing the term data instead of just slugs to my_dropdown_categories() so get_terms() doesn't have to be called, plus a few other improvements (see comments) eg: function my_dropdown_categories( $taxonomy, $current_selected = '', $terms = ...


0

You should look into Bedrock: roots.io/wordpress-stack/ Sounds like it'd be a good starting point for you. roots.io is, IMO, as good as it gets for theme development. I've used it for some time now and at the point where I know Bedrock would be a far better workflow - is a little daunting though so love to know how you get on. In terms of multisite ...


1

Hook the wp_footer action to output markup before </body>: function your_function() { echo '<p>foo</p>'; } add_action('wp_footer', 'your_function');


0

The unfortunate implementation detail of post queries in WP is that they will drag all of post data into memory. It is hard to say if this is definitely the reason in your case, but it might be. Although posts per page is capped at maximum of 999 in admin and it should handle that many normal posts with sufficient memory. The amount per page is stored as ...


0

There can be a few reasons for this. The first is it's literally that the data you're requesting is maxing out. If that's the case use LIMIT to reduce the number of records returned. Select * from table limit 10. Returns 10 records. Other more trickier reasons could be a plugin has gone slightly rogue or you've altered a script somewhere else that is ...


0

Refer to the Codex page for paginate_links for all accepted arguments. The two you want to modify are mid_size and possibly end_size. $output .= paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged') ), 'total' ...


1

Think about it, why would WordPress do anything just because you have defined additional class? It's not magic (neither magical magic or code driven magic). The text widget doesn't appear simply because class exists. When WordPress loads it runs wp_widgets_init(), which executes register_widget('WP_Widget_Text'). So technically you cannot tell it to use ...



Top 50 recent answers are included