question
stringlengths
0
34.8k
answer
stringlengths
0
28.3k
title
stringlengths
7
150
forum_tag
stringclasses
12 values
I'm new to Wordpress, and I wrote the following function: <code> function find_my_image() { if(is_single()) { if (preg_match('#(&lt;img.*?&gt;)#', $content, $result)){ $content .= '&lt;p&gt;Image has been found&lt;/p&gt;'; } else{ $content .= '&lt;p&gt;Sorry, no image here!&lt;/p&gt;'; } } echo $content; } add_filter('...
In your code, $content does not exist. You need to accept the argument into your function: <code> function find_my_image( $content ) { if ( is_single() ) { if ( preg_match( '/(&lt;img[^&gt;]+&gt;)/i', $content, $result ) ) { $content .= '&lt;p&gt;Image has been found&lt;/p&gt;'; } else { $content .= '&lt;p&gt;Sorry, no...
preg_match() not working with post content
wordpress
I'm setting up Woocommerce store for a client who is selling tickets to multiple different live shows. On the night of a show, the box office manager needs to be able to view only orders that contain one specific product (the show). Does anyone know of a plugin that would allow a store manager to either view all orders...
You can simply use the "Search Orders" box on the top right, just enter the product name. Exporting those to csv requires a more tailored approach, not sure if Order/Customer CSV export is up to it (ask WooThemes and they'll be quick to respond)
Filter orders by product in admin
wordpress
I am new to Wordpress and downloaded the 3.5.1 version from my hosting provider. I want to add www in front of my domain and I read from many sources how to do this. Go to settings then general and change it there. Thats fine except my screen in General looks nothing like the instructions I have been following It does ...
You are in the wrong settings page. Your site is a multi-site setup; the URL is set in the site manager, not in individual sites. Go to Network Admin/Sites in the My Sites menu: Select a site to edit: Change the URL: Update You need a subdomain setup to get editable URLs. See Create A Network for the installation guide...
In Settings> > General I am missing some fields
wordpress
I set static page as front page. I need to know if user currently on homepage in my custom plugin. Functions is_home() and is_front_page() doesn't works, since homepage is static page. I can get an id of this page : <code> $frontpage_id = get_option('page_on_front'); </code> But how to get id of current page from admin...
This is why I asked for more code context. I'll have to guess that you are checking for the front page outside of any hooked function, or inside a function that is called too early, before is_front_page() is ready. The following will work. <code> function your_function() { $d = is_front_page(); var_dump($d); } add_acti...
How to check if current static page is frontpage from admin plugin
wordpress
I have created the 2 categories. And these two categories have child category, how can i get the post of the category when I clicked on the category title. Please guide me
<code> &lt;?php // Get the ID of a given category $category_id = get_cat_ID( 'Category Name' ); // Get the URL of this category $category_link = get_category_link( $category_id ); ?&gt; &lt;!-- Print a link to this category --&gt; &lt;a href="&lt;?php echo esc_url( $category_link ); ?&gt;" title="Category Name"&gt;Cate...
How to get the post of category
wordpress
How would I put this together. For plugin Contact Form 7 Data Base how would I add in the "Submitted Login" (user display name) to the search="name" Original Shortcode <code> [cfdb-table form="Contact form 1" show="Submitted Login,your-email,your-message" search="AndrewA"] </code> Tried to put this together a few ways,...
If this works for you in the template: <code> $s='[cfdb-table form="Contact form 1" show="Submitted Login,your-email,your-message" search="AndrewA"]'; echo do_shortcode($s); </code> then you could try: <code> global $current_user; get_currentuserinfo(); $s = sprintf('[cfdb-table form="Contact form 1" show="Submitted Lo...
shortcode change variable base on user
wordpress
I am creating a widget, it needs to store about 10 IDs. Right now I'm using following field method to store each of the ID in a separate field. It stores data of each field in a separately in the wordpress. Is it possible to store the data of all fields in just one row in wordpress for examlpe using an array? <code> &l...
You have to collect multiple fields under the same name like this … <code> name="collect[1]" name="collect[2]" </code> … and adjust your widget logic to this. Here is a very simple demo widget: <code> &lt;?php # -*- coding: utf-8 -*- /* Plugin Name: Store Options as array */ add_action( 'widgets_init', array ( 'T5_Arra...
How to store widget fields data as an array?
wordpress
I am currently pulling in an option drop-down of a specific category using: <code> &lt;?php wp_dropdown_categories('child_of=20'); ?&gt; </code> I would like the initial value of the drop-down to say 'Bedrooms' and not be the first category. Is this possible?
you can set the initial value of categories drop down by passing category id to selected parameter of wp_dropdown_categories function as shown in following code : <code> wp_dropdown_categories( array( 'child_of' =&gt; 20, 'selected' =&gt; get_cat_ID( 'Bedrooms' ) ) ); </code> For more information on this visit this cod...
wp_dropdown_categories initial value
wordpress
I am trying to find a way to link the 'username' in comments from registered and logged in users to their profile pages instead of their website URL. And comments from unregistered users to their website URL as usual. Is this possible? My wordpress version is 3.5.1 and I am using the default theme Twenty Twelve. Here's...
I have written a solution for that some time ago: <code> &lt;?php # -*- coding: utf-8 -*- /** * Plugin Name: T5 Comment author URI to blog author page * Description: Changes the comment author URI to the blog’s author archive * Version: 2012.07.18 * Author: Thomas Scholz * Author URI: http://toscho.de * License: MIT * ...
Linking comments from registered users to their profile pages
wordpress
I created custom post type. I created category called product-categories. I listed all categories in sidebar.php. How to show the sidebar in all the category pages listing all the categories. Sidebar.php code is, 'name', 'order' => 'ASC', 'hide_empty' => 0, 'use_desc_for_title' => 1, 'child_of' => 21, 'hierarchical' =>...
the following code will work as for per your custom post type add the following code in sidebar.php to show your custom post type category <code> &lt;?php //list terms in a given taxonomy using wp_list_categories (also useful as a widget) $orderby = 'name'; $show_count = 0; // 1 for yes, 0 for no $pad_counts = 0; // 1 ...
How to add the sidebar in all category page
wordpress
some templates are chosen from WordPress based on slugs (e.g. <code> category-{slug}.php </code> ). Problem: How can I use the same template for an i18n'ed slug? Example: I have a <code> category-news.php </code> and an english category with slug "news" and german category with slug "nachrichten". But of course "nachri...
Filter <code> template_include </code> : <code> add_filter( 'template_include', 'prefix_translate_template' ); function prefix_translate_template( $template ) { if ( 'category-' . __( 'news', 'your_textdomain' ) . '.php' === $template ) return 'category-news.php'; return $template; } </code> But I think templates based...
How to i18n slugs for templates?
wordpress
I am working on image aggregation site. Is there a wordpress hook or function to upload media especially image if a url is provided to it? Rest I can do with wp_handle_upload function. Thanks
See <code> media_handle_sideload </code> in Codex: <code> $url = "http://s.wordpress.org/style/images/wp3-logo.png"; $tmp = download_url( $url ); $post_id = 1; $desc = "The WordPress Logo"; // Set variables for storage // fix file filename for query strings preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PN...
Hook or function to upload media via url
wordpress
I have a custom post type that has custom meta that I want to be able to filter on the Admin page. Much like the "All | Published | Drafts | and Trash" links located above the post list. I can't seem to find a hook to hook into. Does one exist? stackexchange-url ("This question") isn't exactly what I am asking. I would...
Just like in stackexchange-url ("Adding a Taxonomy Filter to Admin List for a Custom Post Type?") the filter <code> parse_query </code> could be used, but here I'm using <code> posts_where </code> . The row <code> All | Published | ... </code> is controlled by <code> views_edit-{$post_type} </code> and the <code> $view...
Filter Custom Post Type in Admin
wordpress
In a plugin class, I'm successfully creating a new tab on a Member page using: <code> bp_core_new_nav_item( array( 'name' =&gt; __( 'MyTab', 'bp' ), 'slug' =&gt; 'mytab', 'position' =&gt; 200, 'screen_function' =&gt; array( $this, 'mytab_screen' ), 'default_subnav_slug' =&gt; 'mytab' ) ); </code> The problem appears wh...
That is the correct approach. The problem was in the function mytab_screen() I wasn't using 'array' for the 2nd parameter in the add_action for the template call. Nothing fancy, just sloppiness.
how do you point 'screen_function' to a function in the same class?
wordpress
I am writing a plugin that upon activation creates a set of pages. The first page that I create I want to be the parent of the rest of the pages that are added. For some reason, this is not working. Can someone please take a look at my code and tell me what I have wrong? The code I use to add the first page and return ...
Well, it seems as though the page_template property is deprecated according to the WordPress codex .
Add Page With Parent ID
wordpress
I want to show activity loop for certain groups only. If I use <code> &lt;?php if ( bp_has_activities( array(bp_ajax_querystring( 'activity' ),'object' =&gt; 'groups','per_page'=&gt;6 ,'primary_id' =&gt; $group_id, 'page' =&gt; isset($_REQUEST['page']) ? $_REQUEST['page'] : 1 ) ) ) : ?&gt; </code> I can pass one group ...
After getting all the groups_ids i get all activities_ids by doing: <code> &lt;?php global $bp,$wpdb; $groups_ids = implode(', ', $groups_ids); $sql = "SELECT id FROM {$bp-&gt;activity-&gt;table_name} WHERE component = 'groups' AND item_id IN ({$groups_ids})"; $activity_ids = $wpdb-&gt;get_results( $sql); $a_id = array...
Show activities of defined BuddyPress groups
wordpress
I wanted to change the slug of the portfolio of my page, it is actually /portfolio-item/ i went to my <code> custom_post_types.php </code> file and changed the rewrite rule of the slug to my needs, but when i flush my permalink structure all my portfolio items get their permalink changed to <code> mysite.es/myslug// </...
I got rid of the error, it was the theme itself who blocked the portfolio form changing, edited some code from the theme solved it. The website is done in an old theme which is no longer supported :(
Issues when changing permalink Structure
wordpress
From what I have gathered, once a nonce is generated it is valid for reuse for the next 48 hours. Is it safe to code with this in mind? I'm writing a plugin that does a bit of toing and froing with the client via AJAX and want to know if I should just generate a nonce when the page loads and use that for all communicat...
1, the nonce lifetime is about 24 hours by default actually. take a look at wp_verify_nonce function. To be more accurate, the lifetime is controlled by filter <code> apply_filters( 'nonce_life', DAY_IN_SECONDS ); </code> 2, if the lifetime value makes you doubt if it is "an implementation side-effect", you may want to...
Is it safe to assume that a nonce may be validated more than once?
wordpress
My lack of SQL skills has stopped me in my tracks here. I'm trying to select post_id, post_title and two postmeta values - the first has the meta_key of 'search_country' and the second a meta_key of 'search_region'. I think I have a working solution for retrieving just the search_country: <code> $querystr = " SELECT $w...
You need to join the <code> post_meta </code> table twice to the <code> posts </code> table, once for each meta value: <code> SELECT p.ID id, p.post_title title, country.meta_value country, region.meta_value region FROM {$wpdb-&gt;posts} p JOIN {$wpdb-&gt;postmeta} country ON p.ID = country.post_id AND country.meta_key...
Select from wp_post and multiple meta_value from wp_postmeta
wordpress
I have created a media button as such: <code> // Create a media button for pages function aisis_page_button_link(){ global $post_ID, $temp_ID, $iframe_post_id; $iframe_post_id = (int) (0 == $post_ID ? $temp_ID : $post_ID); $url = admin_url("/admin-ajax.php?post_id=$iframe_post_id&amp;codes=aisis-page-codes&amp;action=a...
Check the post type : <code> function aisis_page_button_link(){ global $post_ID, $temp_ID, $iframe_post_id; if ( 'page' !== get_post_type( $post_ID ) ) return; // continue </code>
Adding Media button to only pages
wordpress
Working for couple of Months with Wordpress and developing basic plugins I have the impression that wordpress is not able to handle properly requests if more plugins are activated and mainly because that all of theme are reachable inside of the hole framework. Is there a way to setup the plugins in such a way that each...
To run a plugin only when it is needed the plugin author has to identify the pages where the code actually does something. WordPress offers a surprisingly simple way to do that: the global variable <code> $pagenow </code> . It is set before a plugin is called in <code> wp-includes/vars.php </code> . In a spam block plu...
Wordpress as framework
wordpress
I am having a few issues with a site I am building, on the news page It has 1 featured post from the news category and then under that more news category posts, but missing out the featured news item as I don't want that item repeating. for example page 1 featured post - post 1 post 2 post 3 post 4 post 5 page 2 post 6...
Well first of all, we can get rid of all the <code> query_posts </code> business in the template. There's always a better method than using <code> query_posts </code> . If the primary goal is to have 5 posts on the first page and 4 on all subsequent pages, we can do that very easily before the query happens via a funct...
wordpress category.php query for featured news item, broken pagination and repeating posts
wordpress
On parent page, I've got a grid of custom field values from child pages. All text fields work fine, but I'm having issues with the file URL fields: instead of the URL it returns attachment ID. Here's the code I'm using to display all the fields: <code> &lt;?php //get children of page 4 and display with custom fields $a...
Here's how ACF keeps attachment data: <code> meta_id post_id meta_key meta_value 971 931 doors 666 972 931 _doors field_25 </code> As you can see if you're using <code> get_post_meta </code> it will only ever be able to return you an ID. Since not using <code> get_field </code> you'll need to do the extra step of getti...
Advanced Custom Fields Plugin: Get file URL into Parent
wordpress
I have 2 loops, movie trailers and gaming trailers but gaming trailers is displaying under both Movie Trailers and Gaming Trailer. Each loop displays the post tagged with either <code> Movie Trailer </code> or <code> Gaming Trailer </code> . How do I get posts tagged with "Movie Trailers" under the movies area and post...
You can't add the pre_get_posts action right before the loop. You HAVE to do it in functions.php. It has to be set before the site actually queries the db to set up the loop which happens before your template file is loaded. What you are doing is looping through the exact same query twice, because pre_get_posts can't c...
2 Loops, Only Displaying 1 Loop in Both Loops
wordpress
I'm using the Simple Local Avatars plugin so my bbPress forumgoers can upload their own avatars. Now, when a user logs in, I want his/her avatar to display next to the relevant links (i.e. logout, edit profile, etc.). I tried the call below but it only keeps showing the default mystery man gravatar. <code> &lt;?php ech...
And of course as soon as I post the question, I find the answer. slaps forehead <code> &lt;?php global $current_user; get_currentuserinfo(); echo get_avatar( $current_user-&gt;ID, 48 ); ?&gt; </code>
get_avatar won't show uploaded avatar, only default gravatar
wordpress
I am currently working on a WooCommerce site.I managed to set it up,do some configuration according to my plan.Now i want to display product categories alongside each products in product catalog,and also want to display how many time the product has been sold too. I have done some searching and found this code,which di...
Try looking in the Codex for answers. You will find that <code> get_term_link() </code> creates links to terms. <code> foreach( $parents as $parent ) { echo get_term_link( $parent ); } </code>
How to display product categories and number of sales on WooCommerce
wordpress
In a custom post type I have post titles disabled, however in the list of posts and in the slug it just shows the title as "auto-draft". I want to automatically take two pieces of post-meta and make then the title and the slug. I thought this would work, but I can't make it happen: <code> function set_event_title( $dat...
You are using wrong variable on the following line: <code> $data['post_title'] = $post_title; </code> you should use $event_title in $post_title as following: <code> $data['post_title'] = $event_title; </code> Also Get Post ID from $postarr parameter. Updated Code : <code> function set_event_title( $data , $postarr ) {...
Set post title from two meta fields
wordpress
I am given a WordPress multisite and need to extract information from the site. I have written a stored procedure that recursively builds a tree relationship for posts of a certain kind. Now I am wondering how to push the stored procedure to the databases of all the sites.(Since this is a multisite configuration, each ...
Here are the Steps: STEP 01 : Put code in a Text File Open up a text editor (vi, nano, emacs) and place your code in it. Save it as <code> /tmp/mynewcode.sql </code> STEP 02 : Collect All Databases Names <code> MYSQLCONN=`-uroot -ppassword` SQLSTMT="SELECT schema_name FROM information_schema.schemata" SQLSTMT="${SQLSTM...
Pushing stored procedure to a multisite database in WordPress
wordpress
I simply wonder why <code> &lt;?php var_dump(get_user_meta(4)); ?&gt; </code> doesn't contain an email address of the user. Instead I have to use <code> get_userdata(4)-&gt;user_email; </code> to query the email of the user. Why is that or did I miss something? <code> get_user_meta() </code> seems to provide all other ...
<code> get_user_meta </code> retrieves a single meta field or all fields of the <code> user_meta </code> data for the given user. This means that all the values that are stored in <code> user_meta </code> table can be got using <code> get_user_meta </code> . Email is not stored as meta data so you cant get email using ...
get_user_meta() doesn't include user email?
wordpress
I have added function to functions.php so authors can search only their published content. I would like to add additional "Search my posts" button to searchform.php so only logged in users would see - have this button for searching posts they published. But I can get it to work. :( When I click on any button "Search Al...
You might have to check which button was clicked by user, weather it is search all post or search my post, based on that you can apply filter. Try this.. <code> function search_author($query) { if($query-&gt;is_search) { if($query-&gt;query_vars['author']=='Search My Posts') { $query-&gt;set('author', get_current_user_...
How to Add Additional Search Button?
wordpress
I have developed a WordPress website using a Child Theme, I started with Twenty Ten as the base, then I created a new and improved version with Twenty Eleven as the base and some new features, now I have done it again with Twenty Twelve as the Parent theme. The new features are working mostly great, except when viewing...
During development disable all caching. Short check list: no caching plugins active no caching rules in .htaccess stackexchange-url ("add a time stamp to your theme stylesheets") stackexchange-url ("add a time stamp to editor stylesheets")
Why do some pages on my site use the previous theme?
wordpress
I am writing a plugin that creates an api for a custom post type. Users can comments on the custom post types and the comments are added using WP core comment methods. My question arises when trying to deal with what to do when deleting a comment. I understand what methods to use, but my question is more about the gene...
Do not delete the comment. One comment could have multiple children, and moving the replies up would create a false impression in any case. The real question here is why someone wants to delete a comment and how you could react: The content is obsolete or wrong: Add a note, mark it as outdated. The commenter disclosed ...
Plugin: How should I handle deleting comments?
wordpress
What I'm simply trying to do is grab the featured image thumbnail image from a specified post/page and display that image on any other page somewhere. So for instance, if it's a single post, use the thumbnail from post 9. If it's this page, use the thumbnail from 82, and so on. It doesn't seem as simple as this: <code>...
Looks like this might be the reason why it wasn't working the way I needed. before -> if ( has_post_thumbnail () ) Seems that only relates to the specific post/page you're on, and not the page/page that you're getting the image from - if you don't enter a post ID. But then I tried it with the post ID I was trying to re...
Retrieve a specific post's featured image and show on a different page
wordpress
I am using the WordPress function <code> add_meta_box() </code> to add my own custom metabox. So how can I auto close/hide on page open ? Currently, I just add a CSS class <code> closed </code> to metabox's <code> &lt;div&gt; </code> element via jQuery like so: HTML : (example) <code> &lt;div id="my_metabox" class="pos...
Hook into <code> postbox_classes </code> . <code> postbox_classes </code> is the function which will output the classes for the metabox. <code> apply_filters( "postbox_classes_{$page}_{$id}", $classes ) </code> Your code could look like this: <code> add_action( 'add_meta_boxes', 'add_my_metabox' ); function add_my_meta...
Auto close (hide) custom metabox / set default state
wordpress
I am trying to make the link like this: <code> site.com/forums/user/userid </code> using the code below. I think I messed it up though because it keeps producing an error on this line. <code> $buttons['Edit My Profile'] = site_url('/forums/user/')$current_user-&gt;user_login; </code> Here is more of the surrounding cod...
You are just missing the concatenation operator . Your code should look like this: <code> $buttons['Edit My Profile'] = site_url('/forums/user/') . $current_user-&gt;user_login; </code>
site_url and $current_user producing undesired results
wordpress
I am currently using the following code to display a list with links to posts in a specific CPT and taxonomy: <code> &lt;?php $custom_terms = get_terms('videoscategory'); foreach(array($custom_terms as $custom_term) { wp_reset_query(); $args = array('post_type' =&gt; 'product', 'tax_query' =&gt; array( 'relation' =&gt;...
Ok I figured it out! <code> &lt;?php $custom_terms = get_terms('your_other_category'); $other_custom_terms = get_terms('your_category'); foreach ($custom_terms as $custom_term) { foreach ($other_custom_terms as $other_custom_term) { wp_reset_query(); $args = array('post_type' =&gt; 'product', 'tax_query' =&gt; array( '...
Query for posts in 2 taxonomies
wordpress
i am writing a plugin and after hours and hours of searching for any documentation on WP 3.5 media manager i managed to create my custom media frame that is being called when a user clicks on a custom TinyMCE button in that i added. this is the working code that inserts a single image: <code> onclick: function(e) { var...
I found this plugin. It provides a pretty good example of how to integrate the new Media UI with the admin, and is very well documented: https://github.com/thomasgriffin/New-Media-Image-Uploader/ Maybe that can help you.
WP 3.5 media manager - how to create a working gallery frame
wordpress
I don't understand when to use $post-> ID or $post-> post-> ID with CPTs. I have : <code> $event = get_post( $event_id ); $event_pre_register = get_post_meta($event-&gt;post-&gt;ID, "Event Pre-register deadline", true); </code> Or is it : get_post_meta($event-> ID ... ?
If you have the CPT's ID in the <code> $event_id </code> variable you plug into the <code> get_post() </code> call - why would you not simply just (re)use that for the first parameter of <code> get_post_meta() </code> ? That aside, <code> get_post() </code> returns a post object (instance of WP_Post), which you choose ...
Correct syntax for retrieving custom field in CPT
wordpress
I am working on a WordPress plugin that creates several new tables into the database. It also loads some default data into the tables from CSV files. Most of these are small and loading the data works fine. One, however, is a zip code database meant to be loaded with just over 43,000 rows of data. The first time I trie...
I have some suggestions for you: 1, create MySQL insert queries on your own. 2, combine multiple insert values queries into one like values(1,2,3),(4,5,6) 3, use <code> $wpdb-&gt;query </code> then you need to figure out what the appropriate number of " multiple " is. I've tried with 100 and it worked for me but I thin...
Inserting large amounts of data into a custom table during plugin install
wordpress
When you put a name at the top of your index.php like: <code> &lt;?php /* Template Name: Blog Template */ ?&gt; </code> it will work for front-page and it will also create a new page template. I'm wondering if this is allowed and done on purpose? Are there any pitfalls of using index.php as page template?
You can use it as a page template, just as any file with such a header can be used. That doesn't necessarily mean it's a good idea. The template hierarchy already uses index.php as a last resort if it cannot find an appropriate template for a page/post/listing etc, so a specific page will already have template filename...
Using index.php as page template
wordpress
I must be doing something wrong here. I setup my site with a static front page using front-page.php. I created a page in the admin with a title and chose the front-page.php in the template dropdown. My title shows up fine, however the_content(); does not. I'm not doing anything special as shown below. <code> &lt;?php /...
You don't really have a Loop. <code> &lt;?php get_header(); ?&gt; &lt;div class="content"&gt; &lt;div class="welcome_area"&gt; &lt;div class="welcome_area_title"&gt;&lt;?php the_title('');?&gt;&lt;/div&gt; &lt;div class="welcome_area_text"&gt;&lt;?php if (have_posts()) { while (have_posts()) { the_post(); the_content()...
Static page homepage not showing the_content
wordpress
I've got a piece of text in a div that I want to change on each page of my website. At the moment I'm not sure what function I should be using to do this. Here's what I have so far... <code> &lt;?php $page = is_page(); switch ($page){ case 'home': $content = 'How much money....'; break; case 'about': $content = 'We des...
If you wanted to use your switch statement, you could use: <code> switch ($post-&gt;post_name){ case 'home': $content = 'How much money....'; break; case 'about': $content = 'We design....'; break; case 'services': $content = 'At the....'; break; case 'blog': $content = 'Find out whats....'; break; case 'portfolio': $c...
Using a switch statement in Wordpress
wordpress
I am trying to add a custom WordPress editor field to the General Settings page in the admin. I have it working except that when you save anything with HTML it converts all the code to HTML entities so the HTML displays on the frontend as text. For example... I add a link in the Text editor as <code> &lt;a href="http:/...
I found out I needed to add <code> html_entity_decode() </code> around the value so my final code is... <code> /** * Add Copyright text to general settings menu */ $custom_general_settings = new FD_Custom_General_Settings(); class FD_Custom_General_Settings { function __construct() { add_filter('admin_init', array(&amp...
Custom editor field displaying HTML in Visual editor
wordpress
Here is my basic plugin code. I am just starting from scratch. I will explain the functionality. It is simple, While my plugin is active it will add a new meta box in add new post page just below the tags box. The user can add a value to my text box &amp; i will save that value with post ID to my table. You can underst...
The action <code> save_post </code> is also called during AJAX auto-save requests. But your value is not sent then, so you save an empty value for something that isn't set. Start your save function with: <code> if ( defined( 'DOING_AUTOSAVE' ) &amp;&amp; DOING_AUTOSAVE ) return; </code> See basic examples with more che...
Problem with executing a function on saving a post
wordpress
I am using the article tag with the following code: <code> &lt;article id="post-&lt;?php the_ID(); ?&gt;" &lt;?php post_class('clearfix span4 '); ?&gt; role="article"&gt; &lt;/article&gt; </code> and I would like to add "odd" and "even" to the current <code> post_class </code> . I found the following code on other site...
That fact that this concerns <code> post_class </code> is a pretty thin reason to call the question "WordPress related". Mostly it is just PHP but I'll bite. You can make it easy by setting a variable first. <code> $additional_class = (++$j % 2 == 0) ? 'evenpost' : 'oddpost'; ?&gt; &lt;article id="post-&lt;?php the_ID(...
Odd/even class on article tag
wordpress
I have a wordpress.org blog that I host on my own site. I have the Akismet plugin installed, and in general I keep both up-to-date (e.g. at the moment, Akismet is at version 2.5.7, and Wordpress at 3.5.1). From time-to-time (maybe every week or so), I get a notification email from Wordpress that a (generally spam) comm...
Disclaimer: I wrote parts of the Akismet WordPress plugin, though not the parts in question here. Is Akismet failing to connect to the Akismet service, notifying me, and retrying later? Yes, this is exactly what happens. If Akismet doesn't get a valid response from the servers, it reschedules the check for 20 minutes i...
Why do I get email notifications about comments that Wordpress has already determined are spam?
wordpress
I want to display posts on index page within a links-list, with only the titles, till now i did the job, but now i want to have space between titles and be separated by day. Please check wimp.com and see how the titles are separated. Right now my code is something like this <code> &lt;?php query_posts($query_string.'&a...
Add a variable to hold the previous post's date, and then add a <code> &lt;br /&gt; </code> or something when it changes. <code> &lt;?php $prev_date = ''; // initialize to empty string query_posts($query_string.'&amp;cat=-3'); while (have_posts()) : the_post(); ?&gt; &lt;?php if( strlen( $prev_date ) &gt; 0 &amp;&amp; ...
Show posts in a list separated by day
wordpress
I am working on a Wordpress theme that hides the default WYSIWYG editor and replaces it with a custom module system which is fine and dandy, but I've come to the realisation if someone were to use the theme on a pre-existing site they wouldn't be able to access their previously entered content which is obviously bad. S...
You should really only need to run this on an existing post, since new posts will be created in the manner you specify. <code> add_action( 'load-post.php', 'custom_content_conversion' ); function custom_content_conversion() { if (! empty($_GET['post']) ) { // Get the post object $post = get_post($_GET['post']); // If t...
Hooking into the post editing screen for an existing page only
wordpress
How would I go about hiding a post based on a meta_value selection done on the back end. The usual method is to just change the post status from Publish to Draft however, I want this to work based on a dropdown selection. meta_key being <code> current_status </code> and a dropdown box with meta_value of <code> active <...
Use the <code> pre_get_posts </code> action to alter the main query with <code> meta_query </code> arguments to only select posts with <code> active </code> <code> current_status </code> . This example would work for your main posts page. See Conditional Tags for how to determine when other types of queries are run. <c...
How to show or hide a post based on meta_value selection?
wordpress
On the dashboard under add pages, I have 3 section of blockquotes, under text <code> &lt;blockquote id="section1"&gt;first&lt;/blockquote&gt; &lt;blockquote id="section2"&gt;second&lt;/blockquote&gt; &lt;blockquote id="section3"&gt;third&lt;/blockquote&gt; </code> So, when I try output them in the index.php , I do <cod...
Post content is stored as a single block of data in the <code> *_posts </code> table in the <code> post_content </code> column. It isn't divided up into sections, so what you want is tricky at best. What the <code> the_content </code> functions does is take that block of data from the database, runs one or more filters...
Outputting the blogposts or the_content()
wordpress
Anybody please help me to figure out how to add custom post type in Settings menu (option_page). Basically it is easy for custom admin menu by using: 'show_in_menu' => 'menu-slug' but i like to add this post type under option page.
You can add custom post type in Settings menu by passing 'options-general.php' value to 'show_in_menu' parameter as shown below <code> Example : 'show_in_menu' =&gt; 'options-general.php' </code> Full Code : <code> function codex_custom_init() { $labels = array( 'name' =&gt; 'Books', 'singular_name' =&gt; 'Book', 'add_...
How to add custom post type under option page
wordpress
I've now developed two WordPress plugins and would like to see some sites that use it. I'm looking for a way to find sites that use a WordPress plugin I built. However, the official guidelines , don't allow me to log the hostnames of blogs that install my plugin, for example. Point 7: No "phoning home" without user's i...
No, there is no safe way to know the sites using your plugin. Let's take a look at the options: Add a marker to the rendered HTML, a comment or a meta tag. This would still require a search engine to index these markers and tell you when they are found. But what's more important: your users would serve these extra byte...
Finding WordPress sites using my plugins
wordpress
I'm trying to create a submenu page under ' Users ' which is like the 'All Users' page but for listing users of specific roles only . Let's just call this submenu page 'Customer' . So far I managed to create one with its own columns, but there are still some things that I haven't managed to modify to make the contents ...
Here's how I managed to modify the page. For the submenu highlighting , however, I haven't managed to figure it out, so I resort to jQuery . Here's the code: <code> /* - Set user filter links according to users pages * - Set Role Change dropdown menu * */ function custom_user_filter_links( $views ) { global $wp_roles; ...
Modify custom Users Manage page
wordpress
Below is a code I use to display post views. It is integrated with an options panel which allows users to choose whether to display it. I would like to integrate the div class .postviews directly into the code. I would like to do this because it incorporates a blue background and if the views are not displayed, that bl...
Apart from the fact, that the conditional is based on a WordPress option, this is pure PHP, but anyhoo: <code> &lt;?php $show_views = get_option( 'to_post_views' ); if ( 'Yes' === $show_views ) { echo '&lt;div class="postviews"&gt;' . getPostViews( get_the_ID() ) . '&lt;/div&gt;'; } ?&gt; </code>
Integrating CSS Into a WP Function Call
wordpress
So I am creating my first plugin for positioning ads around my site. I created one separate table where I store ads with all their options, such as position, expire date, active, name, type etc... But Now I need just one field where I can allow users to create categories for these ads, add new, delete existing categori...
Create the ads as custom post types and register one or more custom taxonomies for these post types. You can set up the other meta data as post meta (also known as custom fields). The options table is probably not the best place for these data; because you have to reinvent the wheel.
Can I use add_option for a plugin categories and how?
wordpress
I am registering a custom post type (listing) with a plugin and it has two taxonomies. It all seems to work as expected. I can display individual posts from the CPT using <code> single-listing.php </code> but I can't display a full page using <code> archive-listing.php </code> . I just tried <code> taxonomy-organisatio...
Your setup would mean that archive-listing.php would be used at: http://martcol.co.uk/listing/ However, your URL: http://martcol.co.uk/listing/organisation/children/ Is not a post archive, it's a taxonomy archive, specifically an organisation archive, and so <code> archive-listing.php </code> will never be used for it,...
single-mySlug.php works: archive-mySlug.php does not. Custom Post Type
wordpress
I'm building a theme on top of a starter theme (wp-bootstrap) and am having trouble getting the Nav Walker to show the current menu item. current-menu-item is not there when I use a web inspector on the output html. So therefore I can't style it. This is the code in my template file: <code> &lt;?php /** Loading WordPre...
Since it is working as you expect in the <code> header.php </code> file (but not in <code> sidebar.php </code> ), you could add this into <code> header.php </code> : <code> global $my_nav; $my_nav= wp_nav_menu( array( 'menu' =&gt; 'main-menu', 'container' =&gt; '', 'container_class' =&gt; 'navbar-blue', 'menu_class' =&...
Nav Walker current menu item not displaying
wordpress
I am trying to setup a "Couch Mode" (distraction free reading) on my WordPress blog as laid out in this article . The guide in the article follows these steps: Create a new page in WordPress with slug <code> read </code> Add the following rewrite rule at the top of the .htaccess file: <code> RewriteRule ^read/([0-9]+)/...
Here's a method to achieve what you want internally without adding anything to the .htaccess file. It works by adding a rewrite endpoint named <code> read </code> , so any single post permalink with <code> read </code> appended to the end will have a different single post template applied. For example, if your normal s...
Wordpress in "Couch Mode"?
wordpress
I was looking at the user table and noticed for a super admin ( have access to network admin panel ) and an admin to a network site have same <code> wp_capabilities </code> which is <code> a:1:{s:13:"administrator";b:1;} </code> and also the <code> wp_user_level </code> is <code> 10 </code> for both. So, I was wonderin...
Site admins are stored in a site option as an array of usernames. For example, using SQL in MySQLWorkbench you can do a query such as this: <code> SELECT * FROM wp_sitemeta where meta_key='site_admins'; </code> To get back a serialised PHP array. Modifying this value by adding your username and user ID will make you a ...
Difference Between Admin and Super Admin in Database
wordpress
I want to add some additional HTML markup to specific posts in a loop. For example in the post loop, I want to wrap the post 3, 4, 5 in two divs <code> .extra </code> and <code> .extra2 </code> I want to display post in following order: Post 1, 3, 4, 5, 2 I am trying following: <code> &lt;?php if ($query -&gt;current_p...
You can simply do it by wrapping closing divs in if condition where current_post is equal to 2. I have added it in following code <code> &lt;?php if ($query -&gt;current_post == 0) { ?&gt; &lt;div&gt; Post # 1&lt;/div&gt; &lt;?php } ?&gt; &lt;?php if ($query -&gt;current_post == 2) { ?&gt; &lt;div class="extra"&gt; &lt...
How to close open divs in post loop
wordpress
I've created a basic child image for twentytwelve , and it works as expected. The only issue is that it does not have a thumbnail image in the themes page: How do I set a thumbnail image for my child theme?
Create image file in PNG Format having name screenshot.png and save it in themes root folder.The recommended image size is 880x660. Even recommended image size is 880x660 though it will only be shown as 387x290 but the double-sized image allows for high-resolution viewing on HiDPI displays. For more information see thi...
How to set thumbnail image for a (child) theme
wordpress
Looking to add an action to <code> wp_head </code> but only if the user is in "theme customizer" mode. Does anyone know if there's a conditional for this?
Hook a function to the <code> customize_preview_init </code> action. In that function, do your add_action for the <code> wp_head </code> . The <code> customize_preview_init </code> action runs in the call that renders the frame that the preview page is displayed on, and happens early enough to hook onto wp_head.
Is there a WordPress boolean for "theme_customizer_active()"?
wordpress
How do I display the loop inside a static page? Like the loop when I use the search (which in this theme it's actually working) or on index.php An example for what I'm saying can be seen here: http://www.gaganews.com.br/noticias/ I want a page like this, showing all my posts with pagination, since my home page is kinda...
You could use <code> query_posts() </code> to set up a new loop in your page. Assuming that the posts you want are in the category 'Noticias', with a slug of 'noticias': <code> query_posts( 'category=noticias' ); if( have_posts() ) { get_template_part( 'loop', 'index' ); } wp_reset_query(); // probably not necessary, i...
How to display posts on a static page? (like search loop)
wordpress
I am creating a custom tours and travel theme in which I have created custom post type Cities, Locations, Destinations and i am using custom permalink structure. <code> /%category%/%postname%/ </code> So now I want to append a state name or district name before that city, destination or location name. Let me make it mo...
try this <code> add_filter( 'rewrite_rules_array','my_insert_rewrite_rules' ); add_filter( 'query_vars','my_insert_query_vars' ); function my_insert_rewrite_rules( $rules ) { $newrules = array(); $newrules['(.+?)/custom_post_type_slug/(.+?)/?$'] = 'index.php?post_type=custom_post_type_slug&amp;dynamic_string=$matches[1...
How to embed a new string in url?
wordpress
I have a very simple code in my themes footer <code> if (is_user_logged_in()) { $user = wp_get_current_user(); $aka2 = get_user_meta($user-&gt;ID, 'last_visited_blogs', true); $aka2[] = 'blog4'; update_user_meta($user-&gt;ID, 'last_visited_blogs', $aka2); } ?&gt; </code> What it does is, gets meta value, inserts new en...
You are overwriting the existing values instead you should check if existing values exist and concatenate the new values to existing values if it is exist as following <code> if (is_user_logged_in()) { $user = wp_get_current_user(); $aka2 = get_user_meta($user-&gt;ID, 'last_visited_blogs',true); if($aka2) array_push ($...
update_user_meta duplicates entry
wordpress
I add flexslider to my theme home page via this code.how can I get number of per item? as 1 2 3 4 ...... <code> &lt;?php $args = array( 'post_type' =&gt; 'try', 'posts_per_page' =&gt; 3 ); $query = new WP_Query( $args ); while ($query-&gt;have_posts()) : $query-&gt;the_post(); ?&gt; &lt;li class="featured-game"&gt; &lt...
You can use <code> $item_nr = $query-&gt;current_post; </code> to give you the position within the loop (starts from <code> 0 </code> ). If you need the first item to start with <code> 1 </code> , you can use: <code> $item_nr = $query-&gt;current_post; $item_nr++; </code> Total number of posts found: <code> $items_foun...
Getting WordPress Flexslider Item Number
wordpress
In this momment, in search results appear the post but without categories (I think are hidden) and with the links from posts broken. I have a piece of code in this theme that i think is responsible for this. Here is the code: <code> &lt;?php $post_format = get_post_format() or $post_format = 'default'; ?&gt; &lt;?php i...
I'm unaware about the code written within the condition for search page. But the following code instead of your one would have to work: <code> if (is_search()) { the_content(); } </code> Try and let me know.
Problem with Search Results in WP (not displaying the full posts)
wordpress
Is it possible to have several custom fields with the same name? For example, I have a custom field called "promotion" for a CPT called "event". Sometimes there are more than one promotion applied to the same event, each for a certain type of participant. So I'd like to have one "promotion" custom field with a value "X...
Yes, it's possible to have multiple fields with the same key. When using <code> get_post_meta($post_id, $key, $single) </code> , make sure you set the <code> $single </code> parameter to <code> false </code> (or just leave it off since it defaults to <code> false </code> ). <code> get_post_meta( $post-&gt;ID, 'Event Pr...
Multiple custom fields with the same name
wordpress
I have a query set up to compare the start and end dates for some custom fields. The start date is required for the post; however, the end date is not. This causes some issues with the following: <code> query_posts( array ( 'meta_query' =&gt; array( array( 'key' =&gt; 'start_date', 'value' =&gt; $date, 'compare' =&gt; ...
I know how to do that in pure SQL but I can't get WP_Query to nest conditions in the way required. If it is acceptable, the easiest way to make this work would be to assign an arbitrary far future end date when the data is saved to the database. Something like <code> strtotime("2038-01-01") </code> . That is a bit of a...
Checking if field is set before comparing with meta_query in query_posts?
wordpress
I'm using "Map Categories to Pages" to add categories to pages. When I call the link http://mypage.com/category/catA+catB I get all my articles, that are associated to the categories catA and catB. What I'm looking for is: A) a way to do something similar with pages: call http://mypage.com/pages/catA+catB and get all p...
To display pages in a category archive index: Add category taxonomy to the <code> Page </code> post-type Static pages, by default, do not have any taxonomies associated with them, including the <code> category </code> taxonomy. So you need to register the <code> category </code> taxonomy for the <code> page </code> pos...
Show pages and articles in category search result
wordpress
How to remove the Gravatar image from Username column in the All User admin page?
There seems to be a filter for the <code> get_avatar </code> function. So I just output an empty string to it. <code> function remove_avatar_from_users_list( $avatar ) { if (is_admin()) { global $current_screen; if ( $current_screen-&gt;base == 'users' ) { $avatar = ''; } } return $avatar; } add_filter( 'get_avatar', '...
How to remove Gravatar from Username column
wordpress
I created a custom post type and for debugging reasons i display the Post ID on the Add New ... page. If i refresh the page without saving or even creating a new post,(so i just press f5 on the post-new.php) the post ID is growing one by one. Why is this happening and is this the normal behaviour?
This is normal behaviour, as I understand it. When you load the page <code> post-new.php </code> , you run this function: <code> $post = get_default_post_to_edit( $post_type, true ); </code> where the second argument stands for <code> $create_in_db </code> . If true then this part is executed: <code> if ( $create_in_db...
Why does the page/post ID keep growing when i refresh the post-new.php file?
wordpress
I have a sidebar that displays the 20 latest posts, what I'd really like to do is Ajaxify that loop so there's a load more button at the bottom. The problem is, it's a fairly complicated loop and getting WordPress to work properly with Ajax is not childs play. I'm fairly familiar with jQuery but I'm no expert when it c...
What is the script for you posted here? I hope it is not the script that will be called by the ajax request, isn't it?? Normally a php script for an ajax request looks like this: <code> &lt;?php $output = array(); $posts = new WP_Query( array( 'showposts' =&gt; 20 ) ); foreach ( $posts as $post ) { array_push( $output,...
Ajax loop in sidebar to load post titles/categories
wordpress
I've seen on a few tutorials that there are numbers at the end of the call to save Custom Fields/Meta Boxes on the <code> save_post </code> hook. For example, in the WordPress Codex it gives the following example: <code> &lt;?php add_action( 'save_post', 'my_save_post', 10, 2 ); ?&gt; </code> What do the 10 and 2 mean ...
The 10 is the priority (relative to other added actions) and the 2 is simply the number of arguments that my_save_post() will accept. See the codex .
What do the numbers mean at the end of add_action('save_post')...?
wordpress
I am creating a small blog about my trekking and camping experience. Since different experiences - like campsites, treks and tour operators - have different metadata, I have created a custom post types (e.g. <code> campsite </code> ), associated with custom field types (e.g. <code> price </code> , <code> water_supply <...
That statement grabs a file called content-post-format.php in the theme directory, depending on the post format. Posts will grab content.php since there is no post format. Copy the information out of content.php into single-campsite.php and go from there. Alternatively, you can create a copy of content.php called conte...
Insert custom fields to a custom post type
wordpress
Hoping someone can give me a pointer in the right direction. I'm building a website for my friend who's getting married and they've asked to be able to update the site themselves - fair enough. So, what I've done so far is create my main page in Wordpress and assigned that as the template to the 'home' page. For each o...
Are you using Posts for anything in the site? If not, you could make each person's information a post, and and give them each a category -- ie, "Bride", "Groom", "Bridesmaids", "Groomsmen". Each post could have a title, a description (in the Content area), a Featured Image that you could pull, and an optional Excerpt. ...
Single page Wordpress website - custom fields or meta boxes or something else?
wordpress
I am trying to store SNS share value + comment count on my postmeta, DB. I put code below to accomplish this task, <code> function get_sns_share($post_ID=0) { $url1=get_permalink($post-&gt;ID); $src = json_decode(file_get_contents('http://graph.facebook.com/' . $url1)); $share_count = $src-&gt;shares; // facebook commn...
Within a function or method, the <code> return </code> statement immediately stops the execution of the earlier. Hence the last line never gets interpreted. Switch the order of this: <code> return $social_score; update_post_meta($post_id, '_social_score', $social_score); </code> to this: <code> update_post_meta($post_i...
Store SNS share value via function.php
wordpress
I previously asked and accepted a similar question here: stackexchange-url ("wp_query and comment_parent - select only posts with top level comments") So I'm trying to use wp_query to select only posts that have comments. The problem I'm facing now is I have numerous filters as part of an advanced search e.g. name, loc...
You might try this: <code> add_filter( 'posts_where', 'filter_where' ); $query = new WP_Query($args); remove_filter( 'posts_where', 'filter_where' ); </code> where <code> function filter_where( $where = '' ) { $where .= " AND comment_count &gt; 0 "; return $where; } </code> to get posts with comments.
wp_query select if have comments
wordpress
With custom meta boxes, how would I go about displaying the background image (or color if no image is linked) within the page. Code for the page where I want data to displayed. I want to apply the background color/image to section id="masthead". <code> &lt;?php if (get_post_meta($post-&gt;ID, '_sqcmb_masthead_select', ...
You need to extract the value of the custom metabox (be this background color or background image) and then, once you validate to make sure it has a value, which one is empty or what happens if both have values, to determine an INLINE-STYLING on the following piece of code: <code> &lt;section id="masthead" style="backg...
Display background color or image with custom meta box?
wordpress
hope things are going well. I'm trying to create a member's only section specific for posts of about job opportunities. My goal is to have posts of this category displayed on this page and excluded from the index.php page. I have created a template page by altering archive.php. The category ID for this "employment oppo...
1. CSS/HTML issues are off-topic for this site, per the FAQ. But, have you tried investigating with Firebug or Chrome's dev tools? The answer is obvious in seconds. This page http://www.biz.uiowa.edu/bta/test/ has large headings because of <code> .singular .entry-title { font-size: 2em; margin-bottom: 0.3em; } </code> ...
Posts of specific category on page and excluded from index.htm
wordpress
The code below is meant to display an Advanced Custom Fields Repeater field. I need to have unique values for the "for" attribute of the Label tag, and for the ID value of the trailing checkbox input field. Also, in order for the field label to work correctly, I need the "for" value to match the ID value of the input f...
Try using a "counter" variable for the loop maybe? <code> &lt;?php if ( get_field('ingredients-list') ) { echo '&lt;ul class="ingredientsList"&gt;'; $count=0; while ( has_sub_field('ingredients-list') ) { echo '&lt;li class="ingredient" itemprop="ingredients"&gt; &lt;label for="check-'. $count .'"&gt; &lt;input type="c...
How to Increment ID value within ACF Repeater Field Loop
wordpress
i have this code to limit the comments per user. <code> &lt;!-- #only one comment --&gt; &lt;?php global $current_user,$post; $args = array('user_id' =&gt; $current_user-&gt;ID,'post_id' =&gt; $post-&gt;ID); $usercomment = get_comments($args); if(count($usercomment) &gt;= 1){ echo 'Thank you for your comment'; } else {...
Try this, the code below will generate every comment by the <code> $current_user-&gt;user_email </code> for the author_email, if the <code> $usercomment </code> return something, then there is a comment by the current user so echo "thank you", but if it's not return anything output the form. <code> global $current_user...
One comment per user email per post
wordpress
I am working with the Theme Customizer API and am going crazy trying to find the stored values. The values successfully save and update on the front-end, so they are obviously registered successfully, however, I'm storing the options as theme specific via this method where <code> $this_theme </code> is set as <code> $t...
If your settings are stored as Theme Mods , rather than as a Settings API option , then you need to pass the appropriate value to the <code> type </code> parameter to <code> $wp_customize-&gt;add_setting() </code> : <code> 'option' </code> : Settings API option ( <code> get_option() </code> ) <code> 'theme_mod' </code>...
Color Options from Theme Customizer API not returning via get_theme_mod()
wordpress
I've defined some custom fields using Advanced Custom Fields , and I display these fields as keys and values using <code> get_post_meta </code> , e.g.: <code> &lt;span class="campsite_meta_key"&gt;מחיר:&lt;/span&gt; &lt;?php echo get_post_meta($post-&gt;ID, 'price', true);?&gt; , &lt;span class="campsite_meta_key"&gt;מ...
See the ACF documentation for <code> get_field_object </code> : <code> $field_object = get_field_object( 'price', $post-&gt;ID ); echo $field_object['label']; </code>
Get custom field label
wordpress
I'm using the WooCommerce plugin with WordPress and within my theme I'd like to list all categories within a navigation menu with PHP. I've tried using <code> woocommerce_product_categories(); </code> but I don't want the images, or other HTML elements, just their names (and maybe permalinks). How can I get that data?
taken from that very same function: <code> $args = array( 'number' =&gt; $number, 'orderby' =&gt; $orderby, 'order' =&gt; $order, 'hide_empty' =&gt; $hide_empty, 'include' =&gt; $ids ); $product_categories = get_terms( 'product_cat', $args ); </code> will give you the list of product categories. easy!
WooCommerce: List All Categories
wordpress
I am aware that WordPress provides Plugins a nice way to clean up the db if the Plugin is deleted by providing the <code> uninstall.php </code> hook. You just have to place the cleaning code and it works. But my question is, I have seen a couple of Plugins which is using functions defined in their Plugin file inside th...
I have seen a couple of Plugins which is using functions defined in their Plugin file inside the uninstall.php file. That doesn't work, if the <code> uninstall.php </code> calls one of the plugin's functions, it will produce a <code> Fatal error: Call to undefined function </code> . Unless... (explained bellow). This, ...
uninstall.php file in Plugin to clean DB
wordpress
I am trying to insert a large number of user in to the wordpress db using wp_insert_user(). After inserting each user, I am trying to add an user meta for each user. I am doing like this: <code> $meta_value = //data from an API (e.g.: 19, 34, 1290 etc) $user_id = wp_insert_user( $new_user_data );// it works fine update...
I fixed it doing like below: <code> $meta_value = //data from an API (e.g.: 19, 34, 1290 etc) $meta_value_string = "". $meta_value; $user_id = wp_insert_user( $new_user_data ); update_user_meta( $user_id, 'my_meta_key', $meta_value_string ); </code> Now it works fine.
Problem with update_user_meta() meta_value
wordpress
I want to update a customers blog to a child theme that is based on a newer version of the actual deployed theme. My problem is, the developers of the theme changed the IDs of sidebars. In the old version <code> register_sidebar() </code> was called without providing an ID, therefor WP used numeric IDs. Now developers ...
WordPress actually lists all WidgetAreas that aren't registered. You then are able to drag and drop the widget settings into the new area.
Copy Widget Settings because of changed IDs
wordpress
I did all the following: Deleted the cache in the WP Super Cache settings Added <code> define('DISABLE_CACHE', true); </code> in my wp-config.php Deleted my 'cache' folder under 'wp-content' However a theme php file is still not updating. Can anyone help me?
I found where the problem was. Everything was working correctly, but I was uploading the wrong version of the php file in question. User error, indeed, but in the process I learned a lot about the WP cache.
Cleared wp-cache and file is still not updated
wordpress
I really love using SVG images as I can scale them as big or as small as I want. However, WordPress won't allow me to upload them using the media uploader. How can I change this?
You need to filter the allowed upload file types and add the SVG filetype to the list: <code> function allow_svg_upload_mimes( $mimes ) { $mimes['svg'] = 'image/svg+xml'; return $mimes; } add_filter( 'upload_mimes', 'allow_svg_upload_mimes' ); </code> Also on GitHub
How can I upload SVG images using the media uploader?
wordpress
I have this loop where I loop through every post of my CPT and fetch the title and the content of each post and put it into an array. That is no problem. But as it happens I have created a repeatable field with Advanced Custom Fields that is present in each of these posts. These fields contains images and captions that...
I don't think this is a restrict Wordpress question, but you might try <code> $args = array( 'posts_per_page' =&gt; '-1', 'post_type' =&gt; 'work', 'orderby' =&gt; 'ID', 'order' =&gt; 'DESC', ); $data = array('work' =&gt; array()); $loop = new WP_Query($args); if( $loop-&gt;have_posts() ): while( $loop-&gt;have_posts()...
How to create a multidimensional array with multiple loops
wordpress
If I, for example, create a custom post type named 'tutorial', how do I get it to also show up in places like "Recent posts" , etc?
Hooking the following function with the <code> pre_get_posts </code> filter will add one or more CPTs to the regular archive pages: <code> function wpse94041_cpts_in_archives( $query ) { if( is_category() || is_tag() ) { // more conditional tags possible, if applicable $query-&gt;set( 'post_type', array( 'post', 'tutor...
How to let custom post type posts show in standard post archive (like in homepage)?
wordpress
I have a CPT (defined in <code> functions.php </code> ) that I have set to as non-hierarchical. A lot of content has already been uploaded into the database. If I change the definition to <code> 'hierarchical' =&gt; true </code> , will the change affect any of the posts in that CPT?
No, it will not. It changes just the interface in the post editor: you get the page attributes box to select a parent. All existing post have already a value for the parent: <code> 0 </code> . You can find it in the <code> post_parent </code> property of each post. The only thing that changes now is the ability to chan...
Modifying Custom Post Type after registration (will it affect content?)
wordpress
I am working with a plugin called Advanced Custom Fields. I am looking for help with code for my custom post type template, which is displaying some repeater field data. I have HTML wrapping each sub-field. Sometimes there will be no value for one or more of the sub-fields. How to NOT display the HTML that is wrapping ...
You can use the "get_sub_field" to test for the subfields. If nothing is returned and they are empty, it won't show the content associated with the if statement. <code> &lt;?php if ( get_field('ingredients-list') ) { echo '&lt;ul class="ingredientsList"&gt;'; while ( has_sub_field('ingredients-list') ) { echo '&lt;li c...
Display HTML only if Custom Field has a Value
wordpress
I know this is going to be simple but I can't work it out. I want to create a nav in the footer listing each page and it's child pages. It will look something like this <code> &lt;ul&gt; &lt;li&gt;&lt;a href="parent.html"&gt;Parent&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="childone.html"&gt;Child One&lt;/a&gt;&lt;/li&...
<code> $page-&gt;post_parent </code> is the ID of the parent page. So <code> get_permalink( $page-&gt;post_parent ); </code> … should do it.
Get permalink to page?
wordpress
I use WooCommerce plugin for my shop. I want to skip the PayPal redirection on the "Thank You" page, where users are redirect to PayPal site. I'd like to add to every order also the shipping prices which are different for every product due to product weight and courier distance. I can invoice the customer later with th...
On page <code> class-wc-gateway-paypal.php </code> -> <code> $this-&gt;liveurl = 'http://www.yourdomain.com/page-name/'; </code> Then in the theme <code> functions.php </code> : <code> remove_action( 'load-update-core.php', 'wp_update_plugins' ); add_filter( 'pre_site_transient_update_plugins', create_function( '$a', "...
How to skip woocommerce PayPal redirection?
wordpress
After this question: stackexchange-url ("stackexchange-url There is an answer that suggests deleting past edits directly from database, which would be nice, because I could create queries to delete specific edits only. But, Is this safe? Why?
The revisional feature of WordPress is only for users. That means, that if you don't need them old revisions, you can safely delete them. The system actually doesn't care.
How safe is it to delete old posts edits to save database space?
wordpress
I would like to use this function, but I don't know correctly what is the perfect way.. The code: <code> &lt;li id="post-&lt;?php the_ID(); ?&gt;" &lt;?php post_class(get_the_content() == "" ? "no-content" : ""); ?&gt; &lt;?php post_class(has_post_thumbnail() ? "" : "no-image"); ?&gt;&gt; </code> There are two if state...
Use the <code> post_class </code> filter to test multiple conditions: <code> function wpa_post_class( $classes ) { global $post; if( ! has_post_thumbnail() ) $classes[] = "no-image"; if( get_the_content() == "" ) $classes[] = "no-content"; return $classes; } add_filter( 'post_class', 'wpa_post_class' ); </code> Then yo...
How to use post_class function?
wordpress
I apologigize for the question, as it sounds silly. But I am forced to ask this question, as I didn't find it's answer anywhere. I have about 3 sites on WordPress, and 2 are working absolutely fine. But the 3rd one have some problem with links. I mean, If I go to All Plugins page, and click on Activate or Deactivate or...
Steps you can take to resolve this issue: Download Fresh Install of WordPress from Wordpress.org Deactivate All Plugins Deactivate Theme-Twenty Twelve and Try Activating some other Basic theme like Twenty Eleven Disable Browser Ad-Blocker Add-ons (if any) Hopefully your problem will get solved by taking the above steps...
Links are not working on All Plugins Page
wordpress
I am developing a theme the pages of which (as well as posts) are so different from the home page that I want different widgets on their sidebars. Is there a way to do it? I'm calling the sidebar on single.php this way, exactly as it's on index.php : <code> &lt;?php get_sidebar(); ?&gt; </code> The sidebar.php is this ...
Use Conditional Tags to show content only if a certain condition is met. In your case, you're probably looking to use <code> is_front_page() </code> . <code> &lt;aside&gt; &lt;ul&gt; &lt;?php if ( function_exists( 'dynamic_sidebar' ) ) { if ( is_front_page() ) { if ( ! dynamic_sidebar( 'frontpage-widget-area' ) ) { ech...
How to insert widget areas specific to certain pages (or posts, etc.)?
wordpress