INSTRUCTION
stringlengths
11
999
RESPONSE
stringlengths
0
999
SOURCE
stringlengths
16
38
METADATA
dict
jQuery does not work I am working on a project where I need jQuery for. I added this to my functions, and the scripts are loaded in my header if I watch my page source, but jQuery doesn't work. What am I doing wrong? function stn_script_enqueuer() { wp_register_script( 'ajax-vote', get_template_directory_uri() . '/js/ajax-vote.js', array('jquery') ); $nonce = wp_create_nonce("vote_nonce"); $stn_vote_data = array( 'ajaxurl' => admin_url( 'admin-ajax.php'), 'nonce' => $nonce, ); wp_localize_script( 'ajax-vote', 'stn_vote', $stn_vote_data ); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'ajax-vote' ); } add_action( 'init', 'stn_script_enqueuer' );
Scripts and stylesheets should always be loaded in the head or in the footer via the `wp_enqueue_scripts action hook`. `wp_enqueue_scripts` is the proper hook to use when enqueuing items that are meant to appear on the front end The `init` hook executes before `wp_head` which is to early for script to load in the header. The `wp_enqueue_scripts` action hook is executed right after `wp_head`, allowing scripts and styles to be loaded properly. This also have the benefit of naming script dependencies and ordering scripts and styles to load properly
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "functions, jquery, hooks, actions, wp enqueue script" }
How to get post content from an array of ids? How do I get post content if I have an array of id's. Basically, I have a function that get post content if you provide an ID. but it doesn't work if I have an array of id's. My function is: function get_post_by_id($id){ $post_content = get_post($id); $content=$post_content->post_content; return $content; } Now if I pass an id to this function it will work. For example: $last_post = get_post_by_id(83); print_r($last_post); How do I get `post_content` if I have an array of `ID's`.Something like: $last_post = get_post_by_id(array(83,80,92)); It doesn't work this way now. Please help!
If your first query works you can try something like this : function get_post_by_id($id){ $content = array(); foreach ($id as $key => $value) { $post_content = get_post($value); $content[]=$post_content->post_content; } return $content; } Cheers, phpbits
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "posts, get posts, post content" }
Formatting Multiple add_theme_support Arguments In my `functions.php` I have the following: `add_theme_support( 'post-thumbnails', 'html5', array( 'comment-list', 'comment-form', 'search-form' ) );` …which in WP 3.8.1 disables e.g. featured image (i.e. `post-thumbnails`). My question is how to properly format all these support items in the `add_theme_support` function; is adding two separate function calls right or 'wrong'? `add_theme_support( 'post-thumbnails' ); add_theme_support( 'html5', array( 'comment-list', 'comment-form', 'search-form' ) );`
You need to use one `add_theme_support()` call for each feature. Per the Codex, the proper function call is: add_theme_support( $feature, $arguments );
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "functions, add theme support" }
Replace wordpress login logo with custom text I wanted to replace the wordpress logo which is displayed on login screen with some custom text. Here is the code what I tried so far: function my_custom_logo() { echo '<style type="text/css"> #header-logo { background-image: url('.get_bloginfo('template_directory').'/images/wp-logo.png) !important; }'; } add_action('admin_head', 'my_custom_logo'); It can replace the logo but what should I need to replace it with some text? Any suggestions to make it work?
You will first need to remove the wordpress logo from the login screen. The wordpress logo is added by css, so you will need to change the css and hook that to the `login_enqueue_scripts` action hook function my_login_logo() { ?> <style type="text/css"> body.login div#login h1 a { background-image: none; background-size: 0 0; height: 0; margin: 0 auto 0; width: 0; } } </style> <?php } add_action( 'login_enqueue_scripts', 'my_login_logo' ); Next you can add your custom message function custom_login_message() { $message = "Your custom message goes here"; return $message; } add_filter('login_message', 'custom_login_message'); You can go and have a look at the codex for additional hooks and filters for the login form
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "wp admin, wp login form" }
$wpdb prepare issue with mysql DATE_FORMAT Today, I have a issue in $wpdb. I used $result = $wpdb->get_var( $wpdb->prepare( "SELECT DATE_FORMAT(report_date, '%d-%m-%Y') FROM table WHERE report_id = %d", $report_id ) ); The above code not works because of %d in DATE_FORMAT. How i solved this issue in wordpress
From the Codex page for the WPDB class: > [...] the `prepare` method [...] supports both a `sprintf()`-like and `vsprintf()`-like syntax. Having a look at PHP's documentation for `sprintf()`: > ##Example 6 ... > > // notice the double %%, this prints a literal '%' character > So you can use $result = $wpdb->get_var( $wpdb->prepare( "SELECT DATE_FORMAT(report_date, '%%d-%%m-%%Y') FROM table WHERE report_id = %d", $report_id ) ); for your purposes.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 3, "tags": "wpdb" }
Difference between the 4 Built in RSS Feeds? Can somebody give me an explanation on the differences between the 4 different built in RSS Feeds and why / when I should choose one over the other? Why does WordPress incorporate 4 different ones instead of focusing on 1 universal one? The feeds include: 1) RDF/RSS 1.0 feed 2) RSS 0.92 feed 3) RSS 2.0 feed 4) Atom feed WordPress RSS Feeds Codex
Feeds are not stored, WordPress generate them on request. That means that even if WordPress _can_ generate 4 type of feed, that does not affect in any way performance, but gives the _possibility_ to users to choose a format they like according to reader they are using: is not WordPress fault if there are different types of feed standard. The WordPress preferred way is RSS 2.0, but if an user has different needs, WordPress allow to choose rdf, rss 0.92 or atom. Of course you, as a site owner, can decide to support only one version, it's as simple as: add_action( 'pre_get_posts', function () { if ( is_feed() && ! is_feed( 'rss2' ) ) { // only support rss2 header("HTTP/1.0 403 Forbidden"); exit(); } });
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "rss, feed" }
Can I force WP_Query to return no results? I'm working on a website with a search feature that allows users to search through a lot of post meta. There is a specific search pattern that I would like to forcibly return no results for. The WP_Query technically will find results in the database, but I'd like to override that somehow to force it to return no results to trigger the `if( $example->have_posts() )` to fail. Is there some sort of parameter I can pass to WP_Query like `'force_no_results' => true` that will force it to return no results?
Try 'post__in' => array(0) Simple and to the point. Update: 'post__in' => empty( $include ) ? [ 0 ] : $include,
stackexchange-wordpress
{ "answer_score": 35, "question_score": 26, "tags": "wp query, loop, search" }
Overwrite functions.php of a theme - What if the theme is updated? I have added a shortcode inside a functions.php file of my a Theme. I am wondering that if the theme changes, it might overwrite the current functions.php file. So, is this true? If so, where should I place my shortcode so that even if I update the theme it doesn't go away?
In general Child Themes are meant to be used for customizations on upstream parent theme. However views differ for specific types of customizations. Since shortcodes are related to your content a lot, it might be more robust to considering putting them into simple plugin (or "must use" plugin).
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "themes, shortcode" }
include php file if page_id matches I think this is a simple question: I'm building a plugi, and up until now, if i wanted to include a php file, i would have to know the page_id - i would put the following command in page.php (or whatever page template i'm using): if (is_page(4552)) { include WP_PLUGIN_DIR .'/file_to_include.php'; } now, A bit more background: i now have a hook that creates a post on activation, and saves the post_id using update_options. so, that's how i know what $page_id is. So, to summarize - **how do i dynamically write the code above - in my plugin - assuming I know the $page_id**? Thanks for helping!
Make sure to add it to a hook that fires at or after 'wp' ; Example: add_action( 'wp', 'your_function_name'); function your_function_name(){ global $post; $your_page_id = get_option('your_option_name'); if( $post->ID == $your_page_id ): //your include endif; }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "plugin development, include" }
Get ID of featured image using "get_post_thumbnail_id(the_ID())" - without printing to screen? I'm using the code: get_post_thumbnail_id(the_ID()) to get the ID of a post thumbnail image, but whenever I call this it outputs the ID to screen. I just want to get the value to use in another function, without it echoing anywhere. How do I do this?
You should not use `the_ID()` in this case, since it will _echo_ the `ID`, use instead `get_the_ID()` to return it. So please try this instead: $thumb_id = get_post_thumbnail_id( get_the_ID() ); to get the `ID` of a post thumbnail image. The general rule is that `the_*()` functions will _echo_ the output, but `get_*()` functions will _return_ it. But of course there are exceptions to every rule, so be careful ;-) If in doubt test it, consult the Codex or check out the source code.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "post thumbnails, thumbnails" }
get_the_title($postID) OR get_the_title()? I would like to know which could be more performant between these two approaches of getting data of a post * To use a loop after a `WP_Query($aConditions)` and use functions like `get_the_title()` ... and all the similar functions without passing any parameters * To call `get_the_title($postID)` with the parameter outside the loop
They're both doing the same thing. If you don't pass a post ID, `get_the_title()` will just use the current post and go about it's business. The performance difference between passing a postID and not passing a postID is, if anything at all, is extremely minor. get_the_title() Codex get_the_title() Core Function
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "wp query, query posts, performance, parameter" }
Get current post id in functions.php I have a `wp_localize_script()` function in my functions.php where I need to push the current post ID of the current post to a jQuery file. So I was wondering how you can get the current post ID of a post in my functions.php. These are both not working: global $post; $post_id = $post->ID; global $wp_query; $post_id = $wp_query->get_queried_object_id();
If you hook your localize script function to `wp_enqueue_scripts`, then you will have access to the `global $post` variable. As long as you pick a hook at or after 'wp' you should have access to the `global $post`. <?php add_action('wp_enqueue_scripts', 'YOUR_NAME_scripts'); function YOUR_NAME_scripts() { wp_enqueue_script('YOUR_NAME-js'); global $post; $params = array( 'site_url' => site_url(), 'admin_ajax_url' => admin_url('admin-ajax.php'), 'post_id' => $post->ID ); wp_localize_script( 'jquery', 'YOUR_NAME', $params ); }
stackexchange-wordpress
{ "answer_score": 12, "question_score": 7, "tags": "posts, wp query, functions, id" }
How to query_post custom posts within default taxonomy? I'm trying to query_post custom posts. It works very good with custom taxonomy, but not with default "category" taxonomy. I tried using "category_name" and "tax_query", but it doesn't work for me. My code is: $c_args = array( 'post_type' => 'product', 'tax_query' => array( array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => 'furniture' ) ) ); // The Query wp_reset_postdata(); query_posts( $c_args ); I get no results. As I said - it works with custom taxonomy, but I need to use "Custom Permalinks" plugin, which doesn't work with custom taxonomy. Any help appreciated.
Use WP_Query instead of query_posts(). $cpt_args = array( 'post_type' => 'product', 'tax_query' => array( array( 'taxonomy' => 'category', 'field' => 'slug', 'terms' => 'furniture' ) ) ); $cpt_query = new WP_Query( $cpt_args );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, categories, query posts" }
Is it possible to change the path of a css file that is registered through wp_enqueue_style()? The theme I am using already calls the `wp_enqueue_style` function to enqueue a css file. I want to whether it is possible to change the css file path before it is actually outputted on the page. Why I want to do this? Basically, I want to check if it is a dev or prod environment. Based on that I want to include either the uncompressed or compressed file.
I wonder if you are looking for the `style_loader_src` filter? For example: add_filter( 'style_loader_src', function ( $src ){ // ... your stuff ... return $src; } ); Similarly there exists the `script_loader_src` filter. There's also the `base_url` property of the global `$wp_scripts` and `$wp_styles` objects, but I think that's only used for enqueued native styles and scripts.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 3, "tags": "css, wp enqueue style" }
Create a page that automatically redirects to latest post of a specific tag/category? I'm looking to make a URL like for example: Where the page for `latest-news` will automatically redirect to the latest news article (article with `news` category tag). I then will need to use the link /latest-news in a few different places (menu, and a slider on the front page).
I'm going to list the steps below which worked for me: Step 1) In the **Admin Panel** create a Page called "Latest News" which will have the slug you want `latest-news`. Step 2) In your **Theme Folder** create a blank file and save it as `page-latest-news.php`. Inside the file, add this: <?php $recent = wp_get_recent_posts(array('numberposts' => 1)); $blogID = get_option('page_for_posts'); if(!empty($recent)) wp_redirect(get_permalink($recent[0]->ID) ,307); else wp_redirect(get_permalink($blogID), 307); Step 3) Upload your `page-latest-news.php` file and test it out. I decided to go with 307 redirects because of the Temporary status, which I imagine the latest post will change frequently. Hope it works for you!
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "redirect" }
Why do Wordpress rewriites seem to work differently for posts vs pages? I am creating some simple rewrites in my functions.php file in my WordPress installation: add_rewrite_rule('product1/faqs/?', 'index.php?name=product1-faqs', 'top'); I've noticed that if you hit "product1/faqs" in the browser, it successfully displays the content of "product1-faqs" but keeps the url as product1/faqs (which is desired) but only if it is a POST. If I try this same technique but on a PAGE, the browser URL flicks to "product1-faqs" (undesired!) Why is that? I don't want have to limit ourselves just to posts for the sake of rewrites working as desired...
It's a pretty simple solution - WP_Query utilizes the `name` variable for posts and custom post type posts. It utilizes `pagename` for pages, hence why `?name=product1-faqs` is not working. Use this instead: add_rewrite_rule('product1/faqs/?', 'index.php?pagename=product1-faqs', 'top');
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "php, url rewriting" }
wp_get_attachment_image_src() width and height boolean I have the following code in my theme: <?php $size = 'large'; $postimage = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), $size ); $url = $postimage[0]; $h = $postimage[2] ?> <div style="background-image: url(<?php echo $url; ?>); height: <?php echo $h; ?>;"></div> Here's an example `var_dump` output for $postimage: array(3) { [0]=> string(99) "{base url here}/uploads/2013/10/h3greendeck.jpg?fit=660%2C660" [1]=> bool(false) [2]=> bool(false) } If I remove the `size` argument for `wp_get_attachment_image_src()` to let it use default I get the same result. Why is size returning boolean, when WordPress knows the size of the image? This happens for every single instance of this code, regardless of the post I'm viewing.
This sounds like a description of the JetPack's Photon service. > Photon is an image acceleration and modification service for Jetpack-connected WordPress sites. Converted images are cached automatically and served from the WordPress.com CDN. Images can be cropped, resized, and filtered by using a simple API controlled by GET query arguments. When Photon is enabled in Jetpack, images are updated on the fly. The Photon API includes the `fit` GET parameter: where `%2C` is url encoded comma. It uses the `image_downsize` filter to overwrite the image retrevial with: // Generate Photon URL $image = array( jetpack_photon_url( $image_url, $photon_args ), false, false ); where the `width` and `height` are set to `false`.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 1, "tags": "theme development, images" }
I get a 0 after the result of my ajax requests Every time I do a particular Ajax request at the end of the result I get a 0. Why am I getting this and is there a way to get rid of it? The result is good it's just followed by a zero for some reason.
WordPress does that by default at the end of `admin-ajax.php`. It kind of assumes you'll use one of `wp_send_json()`, `wp_send_json_success()`, or `wp_send_json_error()` to communicate your process' state (or at least terminate the script yourself). All of those use `wp_die()` to terminate the script after sending the response. It's sort of a catch-all response.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "ajax" }
Seperate functions.php for part of site I built a custom WordPress site for some artists. I'm making one page that is entirely different from the rest of the site. Actually, that and a single.php page. It's for a specific new book, and the only reason it's on the same install is that it shares the blog posts. The rest is all specific. These pages don't need any css or js from the rest of the site - in fact, that is getting in my way. I'm having to overqualified everything and I worry that spill over is going to break the main site. They have their own header-books.php and footer-books.php How can I get them to have their own functions.php so that I can pull in css and js that is totally separate from the main site? (ps - it's way too late for multi site or any big ideas) Thank you. * DW
`functions.php` unfortunately is very ingrained part of theme load process. If your architecture is flexible enough you should be able to conditionally unhook related bits. Even if it's not — templates give you complete control over page output. You could go as far as completely omitting `wp_head()`/`wp_footer()` calls and handle assets (semi-)manually if that is shortest way to address requirements.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "css, javascript" }
Display a different image for each page with editor We have several PAGES (about us, contact, services, etc...) On each page, we have an area for an IMAGE. The IMAGE is located in the same location on each page. (lower right corner > above the footer) We want to display a different image for each page: * About Us = smile.png * Contact Us = map.png * Services = tools.png ..as an example. We want the client to use WP Page Edit "About Us" > Then have a custom field for "lower-page-image", and allow the client to upload any image they need to for that specific page. What is the best way to do this? We want to avoid Plug-ins, or creating several separate Template pages.
Use post thumbnails. Add this to your theme’s `functions.php`: add_action( 'wp_loaded', function() { add_theme_support( 'post-thumbnails' ); }); And in your page template get the thumbnail with: the_post_thumbnail();
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom field, images, pages" }
WordPress Displaying Thumbnails Vertically WordPress is displaying my thumbnails vertically and VERY LARGE. Specifically it's displaying WooCommerce product page thumbnails vertically and VERY LARGE. Can't seem to figure out why or what piece of code is responsible for this happening. I already went into WordPress settings > Media, and made sure thumbnail sizes were correct at 150x150. Also tried disabling every plugin minus WooCommerce and that also didn't do the job. This is on a cloned version of the main site that I deployed for testing/development purposes. The address is ` (That is the address directly to the site. The issue presents itself when you go to a page such as ` Here in an image of the issue: !enter image description here
I ended fixing this myself! After a lot of googling, I was lead to look in my wordpress uploads folder to see if Thumbnails were even being generated at all. Turns out they were not being generated! So why? For some reason my php_gd file was disabled in my php.ini file. I uncommented it, ran a regenerate thumbnails plugin in wordpress and viola! It all works now as it should.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "css, javascript, thumbnails, woocommerce offtopic" }
Correct check for any admin page with editor I have read the codex, but found it a bit incomplete. I like to load stuff only on pages where the post editor is visible. This should include custom post types and everything. I am a bit insure about the `get_current_screen()` Object. When to use `base`, `parent_base` ... Would this be the right check? Tested it on pages and posts and seem to be working. Just asking because I am curious if I could to this better. $screen = get_current_screen(); if ( 'post' == $screen->base || 'page' == $screen->base ) { // Load stuff }
Inspect the global variable `$pagenow`, and use `post_type_supports()` to find post types with an editor: function has_post_editor() { global $pagenow; if ( empty ( $pagenow ) ) return FALSE; if ( ! in_array( $pagenow, array ( 'post-new.php', 'post.php' ) ) ) return FALSE; return post_type_supports( get_current_screen()->post_type, 'editor' ); }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugin development, admin, css, scripts" }
Custom post type not displaying all entries This is using a custom post type that I've set up in the functions.php file. What I was hoping to get some advice one was why I have 14 entries in my custom "SPEAKERS" post type but only have 10 showing on my page? What might be limiting it? This is what I put in my functions.php page // Creates Speakers post type register_post_type('speakers', array( 'label' => 'Speakers', 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'hierarchical' => false, 'rewrite' => array('slug' => 'speakers'), 'query_var' => true, 'supports' => array( 'title', 'editor', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'thumbnail', 'author', 'page-attributes',) ) ); This is a screenshot of all 14 of my speakers, but when you go to my speakers page you only see 10. !enter image description here Any advice is appreciated!
You only see ten posts because that is the amount of posts per page set by default in the back end under 'Settings -> Reading -> Blog pages show at most' !Screenshot reading You can either set that to 14 to display all your 14 posts, or you can use `pre get posts` or WP_Query to alter the main query/create a custom query to change the number of posts shown on a page.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, pagination" }
Obtain page data and use regular loop Is there a way to obtain the data from a certain page outside the regular flow, more efficiently than via `get_post($id)`? I know that I can get for example the title with $post = get_post($id); $title = $post->post_title; But I prefer to use the loop, rather than picking every single page element in the way I described above. So what I want, is to read the entire page data, and then perform a 'regular loop', using `the_title()`, `the_content()`, `the_post_thumbnail()` etc. The reason why I ask this is because I'm busy creating a '404 solution' for my theme, where one is able to create and edit a custom 404 page in the WordPress backend.
You need to use `setup_postdata()`. $post = get_post( $id ); setup_postdata( $post ); if(! empty( $post ) ){ the_title(); echo '<br>'; the_content(); } else { echo "No page found matching ID $id"; }
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "loop, 404 error, get post" }
How to store custom user data on the database? I'm developing a WP multi-site network which have a goal of 10,000 sub blogs. The site needs to store custom data related to the user. There are additional 20 fields of data for each user. What is the best way to store data in the WP? 1. Store in a custom table 2. Store in user meta table I'm using a dedicated server for the database. The specs are 16GB RAM - Intel(R) Xeon(R) CPU X3430 @ 2.40GHz Store data in the User Meta table will affect to my site's performance? Thanks
Do you have any data showing that user meta _won't_ work? Until you do — don't mess with it. You are not likely to get from-scratch solutions as convenient and more performant without significant effort.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "multisite, database, user meta" }
cannot upload anything into wordpress I have worpdress 3.8.1. sometimes when i try to upload image, pdf using worpdress functions it gets stuck at 100% and nothing gets logged in the log files so i d onot know what the problem is. however I have seen the following which appear randomly, picture attached!enter image description here
i have found the culprit. `http-authentication` plugin. not sure what it does but it was enabled and ticked as active, so i just unticked it.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "uploads" }
Editing wp-config.php file asks for another installation I edited wp-config.php and now I can't access my existing site and I see the Wordpress installation page! Help! How do I get to my existing site?
(s)FTP into your site, or use a file manager provided by your host, and undo what you did. 1. Then, if you were editing PHP with the built in editor as I suspect, _don't ever do that again-- ever_. It is like working on an airplane while it is in the air. 2. Create a local copy of your site and work locally. Upload to the host when you know the code works. 3. If you enable debugging, you should see clues as to where you went wrong, but you may not be able to do that in your case as it is the config file that is broken. Without knowing specifically what you changed and how you changed it, that is all I've got.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp config" }
Troll the hackers by redirecting them My website is getting somewhat popular, and with the it's increasing popularity there's an increase in the hackers. Last night I visited my security logs and found that everyday approximately 10 people try to access /?author=1 /?author=2 /?author=3 /?author=4 but I don't have any of these user IDs, so a 404 is generated to them. they also run a guessing bots on usernames: admin administrator wordpress Now, I want to troll them... so each time they try to access any of these two: 1. visiting /?author=1..etc 2. trying to login with admin username I want their IP blocked off my site, and redirected to a youtube video. I know the first one can be done with .htaccess trick, but can't quietly get this trick. the second one I guess is done by php, but I have no experience with Wordpress although I'm pretty good with PHP.
I understand this isn't exactly what you're looking for but these hackers are most likely bots and redirecting them won't matter at all. I suppose you could modify the below code if you reallllly wanted to but this will redirect anybody looking for an author back to your homepage. RewriteCond %{REQUEST_URI} ^/$ RewriteCond %{QUERY_STRING} ^/?author=([0-9]*) [NC] RewriteRule ^(.*)$ [L,R=301,NC]
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "php, htaccess, security, wp redirect, hacked" }
Custom taxonomy only shows 0 in autocomplete for terms and "Choose from the most used tags" I have a custom post type (`rezept` that I added a custom taxonomy `Allergiefrei` to. I got this working so far. Adding terms to the custom taxonomy's box works, too, but autocomplete and 'Choose from the most used tags' only shows "0". Here's the code where I register the custom taxonomy: function register_rezept_taxonomies() { register_taxonomy( 'Allergiefrei', 'rezept', array( 'label' => 'Allergien', 'rewrite' => array('slug' => 'allergien') ) ); } add_action('init', 'register_rezept_taxonomies'); I'm defining custom taxonomies and the post type in a plugin.
Turns out you can't use uppercase taxonomy ids. Those work, mostly, but when WordPress sanitizes Ajax calls, everything uppercase is converted to lower case and it won't find the correct taxonomy. The solution is to only define and use lowercase taxonomy ids.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 4, "tags": "custom taxonomy, admin, autocomplete" }
Different versions of Wordpress between local and production First off, I am a WordPress newbie so please be gentle! :) Long story short, I have been given a project in mid-flight. Development computer has Wordpress 3.8.1 setup with Microsoft Webmatrix. A purchased theme with customizations and content exists on this box. The client has an already purchased domain and hosting package from network solutions. Network solutions states they using Wordpress 3.5.1. When it comes to deploying from local to the web to the Network Solutions site, will I run into major pain points with the site being on a newer version? Maybe I'm being overly paranoid but I don't want to tell my developer to keep working on this site if we have to blow everything away and revert to an older version or work entirely online within Network Solutions. **UPDATE: Network Solutions does allow you to upgrade Wordpress to the latest stable version which meant I didn't have to worry about this anymore.**
I would be very afraid to develop on 3.8.1 and try to run the same code on 3.5.1. Things have changed. 3.5.1 is ancient by web app standards. I can't say that I have ever tried to "backport" like that, but it does worry me. Much of your code would work. WordPress itself is pathologically backwards compatible, but if your code uses new features (intentionally or not) you will have trouble. You can install an old WordPress on the development machine, but _3.5.1 is ancient_. It is unwise to run that on a production machine at all, much less to develop a site on it. Additionally, with 3.5.1 you are likely to have numerous plugin and theme compatibility issues. If Network Solutions won't update to a more current WordPress, and won't let you update, the smart move is to not use Network Solutions. If that isn't possible, I would install the legacy WordPress on your development server and build to that.
stackexchange-wordpress
{ "answer_score": 5, "question_score": 0, "tags": "wordpress version, deployment" }
How to get raw unwritten querystring Without permalink enabled, the urls look like ?p=1 and when permalink is activated it's the postname that appears... question .. isn't this a rewritten version of ?p=1 .. When I use $_GET['p'], there is nothing in there... is that normal?
`$_GET` refers literally to `?p=1` part of URL. With pretty permalink if it's empty then there is nothing to access. WordPress processed either case into query variables of `WP_Query` class. You should use `get_query_var()` to retrieve things like this, so in this specific case it would probably be `get_query_var( 'p' )`.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "permalinks, url rewriting" }
Redirect after post deleted On the single template, I am using a delete post link generated by the get_delete_post_link function. When I use the link to delete the post I am currently on, it adds a query string of ?trashed=1&ids=10, but, as expected, the page generates a 404 error as that post is now gone. I'm just wondering if anyone knows an action/filter I can use to detect when the post has been deleted, so I re-direct the page somewhere else afterwards? Thanks!
Maybe you use the hook `deleted_post` and create a rewrite. The hook runs just after a post or page is deleted. Action function arguments is post- or page-ID.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "filters, actions, single" }
Duplicate domain database to local - How? I've noticed that my process is rather slow and i'd like to speed it up. I want to be able to duplicate my database from my domain which is blueharlequin.com and work locally thus speeding up the process. The reason I want to do that is because our website has specific loops that I cannot duplicate without knowing the category ID as well as other things. I've already downloaded wp-db-backup and uploaded the .sql into PHPmyAdmin however everything I click will link me to my website which is not what I want. My question is how do I make it work locally?
I will suggest Wordpress Duplicator, It is best tool for copying your site to any other host/localhost, and its free, I have used it many times and it works every-time with different server settings. Please note that I haven't affiliated with it in any way.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "php, database" }
Wordpress widget title coding I have a problem with wordpress widget titles, some widgets are not affected by theme custom encoding. Here is the codes; function ecce_widget_title($title){ if( empty( $title ) ) return ' '; else $title = explode(' ', $title,2); $titleNew = '<div class="title_w"><div class="widget-baslik-ilk"><h3>'.$title[0].'</h3></div><h3>'.$title[1].'</h3></div>'; return $titleNew; } add_filter('widget_title', 'ecce_widget_title'); All widget's titles must be look like this; But some widget's titles look like this (just text); Where am i doing wrong? :(
The problem is pretty simple: Some widgets do have a title, while others don't. As long as the title filter is present, it works. Example of what the plugin might have: echo apply_filters( 'widget_title', $instance['title'] ); If that filter is not present, there won't be a title.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "widgets, title" }
Get rid of this Strict Standards warning I'm trying to get rid of this warning from my wordpress installation. Strict Standards: Only variables should be passed by reference in xxxxx on line 67 The line with the "faulty code" is this one $wp_theme_name = next(explode('/themes/', $stylesheet_directory_uri)); However, if I do pass the value per reference as requested, the WP doesn't load anymore. Can you please help me to understand how to fix this? Thanks Andrea
This occurs because you do the `explode()` call inside the `next()` call. The reason I think is, by strict standards you shouldn't pass a function to a function like this, because, like @AndrewBartel said, of reference, which would be missing. Doing it like shown below should work and would be correct: $nval = explode( '/themes/', $stylesheet_directory_uri ); $wp_theme_name = next( $nval );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "php, warnings" }
Is it possible to add a filter for the output of nav-menu items in admin? I want to remove certain input fields on the admin screen for nav-menus for specific menu positions. I've used filters to filter front-end output but not for admin output. Is there a filter available for this purpose? For example, I want to remove the option to add a `title` attribute to menu items, only if the menu is used in 'position-x'. Filters such as `nav_menu_link_attributes` and `wp_nav_menu_args` all seem to be to filter the front end output.
These fields are created in `Walker_Nav_Menu_Edit::start_el()`. To change or to remove them, create a custom walker (example for another walker) that extends `Walker_Nav_Menu_Edit` and uses other or less fields. Then filter `wp_edit_nav_menu_walker` and return the class name of your walker. Pseudo-code: class Walker_Nav_Menu_Edit_Simple extends Walker_Nav_Menu_Edit { public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { /* Magic here. */} } add_filter( 'wp_edit_nav_menu_walker', function() { return 'Walker_Nav_Menu_Edit_Simple'; });
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "menus, filters, admin menu" }
Gravity Forms | Form Object is NULL I am trying to customize some gravity forms behavior. Therefore I've tried to hook into gforms from my theme. Unfortunately the form object is always `NULL`. Why is that the case? Example code: 1) add_action('gform_confirmation', 'myCustom_gform_confirmation'); function myCustom_gform_confirmation($confirmation, $form) { var_dump($confirmation); var_dump($form); die(); } 2) add_action('gform_after_submission', 'myCustom_gform_after_submission'); function myCustom_gform_after_submission($entry, $form) { var_dump($entry); var_dump($form); die(); }
By default, the add_action function is only going to pass 1 parameter, but you can define how many do you have / need > $accepted_args (int) (optional) The number of arguments the hooked function accepts. In WordPress 1.5.1+, hooked functions can take extra arguments that are set when the matching do_action() or apply_filters() call is run. So change your code to this: add_action('gform_confirmation', 'myCustom_gform_confirmation', 10, 4);
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "hooks, plugin gravity forms" }
wp_postmeta store multiple values in one key I am currently storing some data in a custom field like this: $get_ref = $_SERVER['HTTP_REFERER']; $ref = get_post_meta($post->ID, 'page_ref', true ); $ref[] = $get_ref; update_post_meta($post->ID,'page_ref', $ref); The above updates the post_meta but doesnt overide it. I would like to save additional data to the same value that is saved above. The above produces this: Array ( [0] => [1] => ) I would like something like this: Array ( [0] => array( 14/04/2014) [1] => array( 10/01/2014)); Any ideas how i can achieve this?
If I follow you correctly you want an array of arrays. $get_ref = $_SERVER['HTTP_REFERER']; $ref = get_post_meta($post->ID, 'page_ref', true ); $ref[] = array($get_ref); //or $ref[][] = 'xyz' ...if you prefer update_post_meta($post->ID,'page_ref', $ref);
stackexchange-wordpress
{ "answer_score": 1, "question_score": -1, "tags": "post meta, array" }
$wpdb->get_var - What value is returned when zero records are found? I have the following code: $queryPermission = $wpdb->get_var( $wpdb->prepare("SELECT Active FROM testers WHERE user_id = '$user_id' ")); if($queryPermission == NULL OR $queryPermission == 0) { header ('location: noaccess.php'); } else { } When the SQL returns records the $queryPermission variable is set to 1 which is great. However when the SQL returns no records the variable $queryPermission returns nothing. I then want to try and pick up on this and redirect the user when that variable contains nothing. I have tried "NULL" and "0" but neither of those seem to work. I was wondering, how can I pick up the case where nothing is returned by SQL using get_var? Thanks :)
First, you're using prepare() wrong. Should be this: `$wpdb->prepare("SELECT Active FROM testers WHERE user_id = %s", $user_id)` Or even better (%d) represents numeric value as oppose to %s which is string: `$wpdb->prepare("SELECT Active FROM testers WHERE user_id = %d", $user_id)` If you have any debugging enabled, it will throw an error from your code. Which may make your location header not work properly. Second, the get_var() function indeed returns `null` when there are no results. Third, setting a location: header without actually exiting afterwards may cause your header to be overwritten by something else later.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "database, mysql, sql" }
Adding body class when post contains a specific shortcode **Simple shortcode function :** function my_shortcode_function($atts,$content=null){ // Do something return $content; } add_shortcode('my_shortcode','my_shortcode_function'); I wonder how to add more extra body class when user use this shortcode in contents. **I can't do something like :** function my_shortcode_function($atts,$content=null){ // Do something add_filter('body_class','my_body_class'); return $content; } function my_body_class($classes) { $classes[] = 'foo'; return $classes; } add_shortcode('my_shortcode','my_shortcode_function'); Any idea ?
I am doing something like this in one of my plugins: function my_body_class( $c ) { global $post; if( isset($post->post_content) && has_shortcode( $post->post_content, 'your-shortcode' ) ) { $c[] = 'your-class'; } return $c; } add_filter( 'body_class', 'my_body_class' ); I'm not sure it was really necessary, but I probably can't remove it now either. TheDeadMedic is right, you should think about whether you really need to do this.
stackexchange-wordpress
{ "answer_score": 8, "question_score": 3, "tags": "functions, filters, shortcode, post class" }
Pages with posts filtered by category My site has a few categories, such as "business", "techology", "news" etc. I'd like to display the latest posts from most categories on the front-page, except for a few special ones which I can filter out as described here. Is there an easy way to add pages in such a way that they automatically display all recent posts from a given set of categories? E.g. a "business & technology" page which automatically displays the most recent posts categorized under "business" or "technology"?
Adding a menu with category items / sub-items does the job here.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "categories, pages" }
how to add a div inside wp_page_menu Right now I'm using the `<?php wp_page_menu('menu_class=nav'); ?>` function, which gives this result: <div class="nav"> <ul> <li class="page_item page-item-5"></li> <li class="page_item page-item-7"></li> <li class="page_item page-item-9"></li> <li class="page_item page-item-11"></li> </ul> </div> Obviously, in every `li` tag there is an `a` tag; so my goal is to add a `div` tag inside the `li` tag and under the `a` tag. How can I do that? I know that I have to create a function in `functions.php`, but I don't know which one. Thanks!
The question is light on detail but I'd lean toward a custom Walker: class My_Page_Walker extends Walker_Page { function end_el( &$output, $page, $depth = 0, $args = array() ) { $output .= '<span>After the Anchor</span></li>'; } } $args = array( 'walker' => new My_Page_Walker ); wp_list_pages( $args ); That should insert content just before the closing `</li>` with is what I think you want.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "php, menus" }
Show Pages in Categories I created category function by adding this code to functions.php: function page_category() { register_taxonomy_for_object_type('category', 'page'); } // Add to the admin_init hook of your theme functions.php file add_action( 'init', 'page_category' ); But the thing is that when I go to a category page, the page does not show the pages that are in the category. I read it is because categories are meant to show only posts. Is there any way show pages in categories, without using a plugin? Thanks!
Have you try: function my_custom_show_pages_in_category( $query ){ if( $query->is_category() && $query->is_main_query() ){ $query->set('post_type', array('post', 'page' ) ) ; } } add_action('pre_get_posts', 'my_custom_show_pages_in_category' ); See more: Codex
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "categories" }
How to query categories with Advanced Custom Fields? I'm currently using Advanced Custom Fields and I was wondering if anyone know how to filter categories by custom fields? I have a custom field in my categories using the checkboxes field. I want to make a page that will list categories that contain a specific checkbox field that is ticked. For example I have 3 checkboxes in my categories which are Romance,Action & Drama. I have ticked checkbox Action and I want to list categories on the page that have ticked checkbox Drama. It is kind of similar to this tutorial < except I want to get categories instead of posts. What’s the easiest way to do this cause I’m not a programmer?
Try something like this : $value = get_field('field_name'); Try whole process based on this < $value = get_field('field_name', $category->cat_ID);
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "categories, custom field, query, advanced custom fields" }
Can't get Category link inside get_posts I created a simple function to display the latest posts. Inside the function there is a conditional to display the post category. I found that to display the category name, using $category = get_the_category($post->post_ID); $category[0]->cat_name; // I want to display only the first category do the job, but can't find how to display the link to the category. Tried to use `get_category_link($post->post_ID)` but no changes, the link still redirects to the current page. The goal is to redirect to category archive. Appreciate any help.
If you can add your code, It may help for everyone. By reading you question. By default normally that `get_category_link` is have to work. Just use `global $post` before your `loop`. If is not work. What you have to do is. 1. Grab the category id using your `@category` variable. (you can use `print_r($category);` or `var_dump($category);` after your code `$category = get_the_category($post->post_ID);`) 2. Then use `get_category_link(pass your grabbed category id)` I'm sure it will work. For more info. Read this CODEX
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "get posts, categories" }
Wp_Mail and Contact Form 7 I have a problem. I've used add_filter('wp_mail_from', 'new_mail_from'); add_filter('wp_mail_from_name', 'new_mail_from_name'); function new_mail_from($old) { return '[email protected]'; } function new_mail_from_name($old) { return 'MySite.com'; } To overwrite default From email WordPress ([email protected]) And this is Ok, But Contact Form 7 Form was overwritten by the same function too. I want CF7 to send `[your-name] [your-surname] <[your-email]>` to email. Not MySite.com ([email protected]) Is there a way to get rid of this bug?
try this one add_filter('wp_mail_from', 'doEmailFilter'); add_filter('wp_mail_from_name', 'doEmailNameFilter'); function doEmailFilter($email_address){ if($email_address === "[email protected]") return '[email protected]'; else return $email_address; } function doEmailNameFilter($email_from){ if($email_from === "WordPress") return 'MySite.com'; else return $email_from; } This checks if WP is going to send mail as a system (as wordpress@something) and if so, changes to your setting. Otherwise, is using inputs data (mail and name).
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "wp mail" }
Custom Post Type doesn't show Draft and Trash Options I have custom post type "Pdf"section.But there is no options like Draft and Trash..!kindly find out this on attachment
You must place (delete) some posts in trash bin first to make this options appear. The same with draft. You must first assign some post as "Draft" in edit screen. As I see in your screen, all your PDF CPT are published. So there's nothing in trash, and nothing is a draft.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "custom post types, custom taxonomy" }
display post tags on single.php inside loop I want to display the tags of the current post in the single.php and do the following: <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <h1 class="single_h"><?php the_title(); ?></h1> <p class="single_subline"><?php echo get_post_meta($post->ID, 'subline', true) ?></p> <!-- everythings fine til here --> <p class="single_tags"><?php echo wp_get_post_tags($post->ID); ?></p> <?php endwhile; endif; ?> and everything just works fine, except the `wp_get_post_tags` method. All I get displayed inside the `.single_tags` is the string `Array`. I am new to wordpress and would like to know what I am doing wrong. Thanks
You're getting `Array` because that's exactly what `wp_get_post_tags` returns; an array (and when you try and echo one in PHP it'll simply output `Array`). As @Chip Bennet suggested, use `the_tags()` instead, which outputs an HTML string.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "loop, array" }
Wordpress function/template tag to get first n words of the content OK, this might be a duplicate, I was just unable to put my idea in proper search terms, sorry for that! Is there a built-in function or template tag to get the first `n` words of the content? I mean `the_content()`. Thanks!
Yep, `wp_trim_words()`: <?php $trimmed = wp_trim_words( $text, $num_words = 55, $more = null ); ?> Or in your case: <?php echo apply_filters( 'the_content', wp_trim_words( strip_tags( $post->post_content ), 55 ) ); ?>
stackexchange-wordpress
{ "answer_score": 10, "question_score": 3, "tags": "functions, content, template tags" }
Query posts by a type and another type only if post is in specific category I have a featured post type and a reviews post type. I would like to include reviews of a certain category (I use categories from the posts type) as well. How could query args be crafted? A crude example: get_posts(array('post_type' => array('featured-posts', array('review-posts', 'featured-category')) Need to fetch all the posts in the featured-posts type, also all the posts in the review-posts type if the assigned category is feature-category. UPDATE: Ended up not needing to implement this but I think Stephen S had the best guess.
Untested, but I think you'd need to do two separate queries and merge them together: $args = array( 'post_type' => 'featured-posts' ); $featured_posts = get_posts($args); $args = array( 'post_type' => 'review-posts', 'category_name' => 'featured-category' ); $review_posts = get_posts($args); $result = array_merge($featured_posts->posts, $review_posts->posts); $final_query = WP_Query($result);
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "custom post types, wp query, get posts" }
Force WordPress to load a specific template How would I force WordPress by code to load a template file on my home page? I know how to do it via the backend but I would like to create a plugin and have the option to set the front page from inside the plugin. Basically, I am looking for the code to force loading a template when the home page is being loaded. So instead of the `index.php` it would load the plugin template. I can't find anything about this.
Depending on your _home_ page, you either can set up a template file `home.php` (archive) or `front-page.php` (static page). In the according file, you can do whatever you want. Run additional queries, load content from whatever source etc. If this is not what you want, then you can have a look at the `template_include` filter hook. If you want/need to do more than just load a specific template file, you might want to have a look at the `template_redirect` action hook.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "customization, templates" }
Wordpress with php 5.5 and zend opcache I currently updated/upgraded my php to 5.5.11 and want to use the opcache that comes with it. I enabled the cache and added a few settings to php.ini zend_extension=/usr/lib/php5/20131313/opcache.so opcache.memory_consumption=128 opcache.interned_strings_buffer=8 opcache.max_accelerated_files=4000 opcache.revalidate_freq=60 opcache.fast_shutdown=1 opcache.enable_cli=1 But is this enough? Can i use wordpress caching plugins or there is no need? I used W3 total cache together with apc until now. Which wordpress caching plugin should i use now? Any other settings of opcache i should change?
Opcache is transparent for WordPress (as it is to any PHP application). However if you had been using APC for object cache (key/value store) via plugin — that function is not available in new bundled Zend cache, it _only_ does opcode caching. You would need to replace object cache with something different (APCu/Memcache/Redis/etc).
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "php, cache, plugin w3 total cache" }
Wordpress: How to make a subsubdirectory **I have a multiple word press installations that I am trying to reduce to one.** Here is what it currently looks like: Installation 1 = www.example.com Installation 2 = www.example.com/foo Installation 3 = www.example.com/foo/bar How do I make it into one installation like this: www.example.com/foo/bar Where `/foo` and `/foo/bar` are two different pages. Optionally: How do I do this: www.example.com/baz/bar Where `/baz` does not do anything (like a 404) and `/bar` is the actual content. Thanks for the help!
You can create sub directories by making parent pages: Say you want it like this: example.com/topicnamebutnocontent/informationontopic _Note:`/topicbutnoname` is a page/direcory that has no content._ * * * You can create it this way: * Make a blank page (it does not have to be blank) E.G. `topicnamebutnocontent` * Make a page that you want to fill with your content E.G. `informationontopic` * Set `informationontopic`'s parent page to the blank page E.G. `topicnamebutnocontent` * Double check that the permalink/address is correct with what you want. And that should create the directory structure that you want! Have a great day!
stackexchange-wordpress
{ "answer_score": -1, "question_score": 0, "tags": "links" }
Multiple Conditions for Child Page Title I've been trying to work with Conditional Tags and cannot wrap my head around this problem. PHP novice here. On sub-pages I need to display the parent page title as well as the page title. I have it working with this: <h1><?php echo get_the_title($post->post_parent);?></h1> <h2><?php the_title(); ?></h2> But the problem I have now is that on the parent pages the page title is displayed twice, as the parent page title and the page title. Instead, when on a parent page, I need the `h2` to display "Select a sub-page", if there are child pages...or display nothing, if there are no child pages. Something like this is what I'm thinking is possible: <h1><?php echo get_the_title($post->post_parent);?></h1> <h2> <?php if is_parent_page_without_children() {echo '';} ; elseif is_parent_page_with_children() {echo 'select a sub-page';} ; else the_title(); ?> </h2>
I found this in the Conditional Tags codex, section 2.12: > "Note: There is no function to check if a page is a sub-page. We can get around the problem: if ( is_page() && $post->post_parent > 0 ) { echo "This is a child page"; } So I've altered it as below and will just use the wp_list_pages function's "title_li" attribute to display "select a sub-page" (not exactly what I was looking for but simple enough and I can work with it for the design of the website I need it for). <h1><?php echo get_the_title($post->post_parent);?></h1> <h2><?php if (is_page() && $post->post_parent > 0 ) { the_title();}?></h2> <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 2, "tags": "title, conditional tags, child pages, children, get the title" }
Can I use images as anchor tags with <?php previous_post(); ?><?php next_post(); ?> Rather than displaying the title of the next page, I would like to display a large arrow that can be clicked on. To do this I shall either be using image files, or the __tag. Can this be done?
Well, yes, of course. Take a look at this reference: < < You can customize it however you like, so you can simply put an html image tag in there. The function must be used in the loop to work. I'd do it like this: <?php previous_post_link('%link', '<img src="Image URL" width="20" height="20" alt="%title" />'); ?> The first parameter controls what comes before and after the link. Because we don't want anything before or after the link, but within, it's just the link. The second parameter is crucial. It says what text should be linked. Here, instead of text we put in the image we want. I've also added the post title as alt attribute. Same way applies to the next link :)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "posts, images, pages, previous post link, nextpage" }
Personal page for every user (not just authors) I've got a page displaying all WP users using get_users() and get_userdata(). I need an individual user page automatically (with its own slug) generated for each new user added. I'm a bit clueless about how to achieve that. Any suggestions?
I guess what you're looking for is an author template. You can create an author.php in your template folder and arrange the information in there like you want to. It will be a general template for every user then. You can access the author page if you visit example.com/author/author-slug/ To give an example: < I'm sorry it's a german site. However, you see that on this author page all posts from this author are displayed. But like I said, you can put whatever information you want into the template, like the description ect. I guess it's the easiest way. Reference: <
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "pages, users" }
Permalink issue only with numbers I use wp-e-commerce plugin and when I write a url like "mysite.com/event/testevent" very thing is ok and wordpress shows the correct page. In case that the event is a number like "mysite.com/event/123456" wordpress shows me the products page. I follow this post but my issue continues to exist.
Unfortunately numeric slugs seem to be not supported by WordPress, see long running trac ticket #5305 (permalinks broken when article name is numeric).
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugin wp e commerce" }
How can I added the post's Categories to the site's top menu (like a page)? Instead of adding pages to the top menu, is there a way to add a dropdown menu with all the categories, or adding individual categories to the top navigation menu? I am using WP 3.9 with Shaken Grid Free theme.
When you're under Appearance > Menus, there should be a link in the top right-hand corner of the screen titled "Screen Options." Check "Categories" or anything else in order to add other items to the menus. This is useful in other pages of the dashboard as well, because some important items (post revisions for example) are hidden there.
stackexchange-wordpress
{ "answer_score": 2, "question_score": -2, "tags": "menus, themes" }
how to return the wordpress path to the new site Please how do i return to the default path something like this after working on the wordpress installation to
If I have read this correctly... If you want to have your url as fittergroup.com but leave all your files in fittergroup.com/blog take a look at the Wordpress documentation on 'Giving WordPress Its Own Directory' In your 'General' settings panel: > In the box for WordPress address (URL): change the address to the new location of your main WordPress core files. Example: < > > In the box for Site address (URL): change the address to the root directory's URL. Example: http:// example.com
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "installation" }
Upgrading themes never works I have a Wordpress installation running on my own server at home, serving a domain name I bought. It's running on Debian Linux, currently installed under `/usr/share/wordpress`. When I'm in the Admin panel, I see notifications for updates to the themes or plug-ins. So, I SSH into my server, turn on the FTP daemon, then start the update. Below is an example output: Downloading install package from Unpacking the package… Installing the plugin… Could not create directory. /var/lib/wordpress/wp-content/plugins/akismet/ Plugin install failed. This is starting to get a little annoying. The directory exists, and the user that the FTP is running on (www-data) has write access to the folder. Why can the Updater not remove the old plug in, then install the new one? * * * Meta Discussion about being on or off topic
`Could not create directory` is still a permissions error; have you checked Changing File Permissions « WordPress Codex? Are wp-content, themes and plugins 755? > Any file that needs write access from WordPress should be owned or group-owned by the user account used by the WordPress (which may be different than the server account). For example, you may have a user account that lets you FTP files back and forth to your server, but your server itself may run using a separate user, in a separate usergroup, such as dhapache or nobody. If WordPress is running as the FTP account, that account needs to have write access, i.e., be the owner of the files, or belong to a group that has write access. In the latter case, that would mean permissions are set more permissively than default (for example, 775 rather than 755 for folders, and 664 instead of 644).
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "updates" }
How to show part of the_content? i wanna show 20 chars of the_content i tried this but doesn't work for me . <?php $content = ''; $content = the_content(); $count_content = strlen($content); if($count_content > 20 ) { $description = substr($content, 0,20,'UTF-8'); echo $description ; } else { echo $content; } ?>
Check out the Wordpress Codex reference page for `the_excerpt()` as it is a built-in way of doing what you're looking to accomplish: * < EDIT: it also has an example for shortening the excerpt beyond the default length.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "php, posts, theme development" }
Detecting errors generated by $wpdb->get_results() How do I detect errors when using $wpdb->get_results()? For example: $result = $wpdb->get_results("SELECT * FROM this is not a valid query"); The preceding code doesn't generate any exceptions or errors; it simply sets $result to an empty array. How do we reliably detect errors generated by get_results()?
There is a class variable that stores the last error string - $wpdb->last_error. By the looks of the way $wpdb is coded, if the query succeeds, $wpdb->last_error will be an empty string, if it fails, it will be the error string returned by MySQL. So something like this would do the trick. $result = $wpdb->get_results("SELECT * FROM this is not a valid query"); if ($wpdb->last_error) { echo 'You done bad! ' . $wpdb->last_error; }
stackexchange-wordpress
{ "answer_score": 11, "question_score": 11, "tags": "database, wpdb, errors" }
Wordpress upload file action hook I have a custom post type called "Magazine" shown in the admin interface. Everytime a user **uploads** a **file** in the wp-admin to my custom post type "Magazine", I want to fire a hook because I have to process the file. Is there any **action hook** I can use in this case? Hope someone can help me.
Try this way, should work well function cpt_from_attachment($attachment_ID) { global $current_user; get_currentuserinfo(); $attachment_post = get_post( $attachment_ID ); $type = get_post_mime_type($attachment_ID); // DO WHAT YOU NEED } add_action("add_attachment", 'cpt_from_attachment');
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "uploads, hooks, actions" }
TinyMCE 4.x : How to customize toolbar on wp_editor() Since upgrading to Wordpress 3.9 (which includes TinyMCE 4.x), I have problems customizing the editor, displayed via `wp_editor()` In the example below, I want to disable the 'fullscreen' button, but this doesn't work. $settings = array( 'textarea_name' => 'description', 'quicktags' => false, 'media_buttons' => false, 'teeny' => true, 'tinymce'=> array( 'theme_advanced_disable' => 'fullscreen' ) ); wp_editor( $content, 'description', $settings ); Unfortunately, the documentation for TinyMCE API 4.x isn't as helpful to me as the 3.8 one
Try this: replace 'theme_advanced_disable' => 'fullscreen' with 'toolbar1'=> 'bold,italic,underline,bullist,numlist,link,unlink,forecolor,undo,redo' Also, remove `'teeny' => true,`
stackexchange-wordpress
{ "answer_score": 14, "question_score": 6, "tags": "tinymce, wp editor" }
Change default screen option value for posts per page I want to change the default screen option value for posts per page in the wp-admin area when listing posts in `pending` mode. The default value is set to `20`. Changing the value directly in the Screen Options tab will only affect the user, not all users like this answer suggests. Any workable solution?
Just an addiction to @KrzysiekDróżdż answer. When viewing a specific post status the url query string variable `'post_status'`, is set to the name of the status, so you can use `$_GET['post_status']` to narrow the effect of @KrzysiekDróżdż code only for pending posts: function my_edit_per_page( $result, $option, $user ) { $status = filter_input( INPUT_GET, 'post_status', FILTER_SANITIZE_STRING ); if ( $status === 'pending' && (int) $result < 1 ) return 20; // or whatever you want } add_filter( 'get_user_option_edit_post_per_page', 'my_edit_per_page', 10, 3 ); // for posts
stackexchange-wordpress
{ "answer_score": 3, "question_score": 2, "tags": "posts, list, screen options" }
How do I publish portfolio items with a future date? I am trying to publish portfolio items with a future date (using for an event based website) and I can't see to find any plugins or anything. I have seen them for generic posts, such as "The Future is Now" and things like that. I don't know wordpress well enough to code my own solution to this :/ Does anyone know what I could do? Cheers **EDIT** \- I mean I want it published now, but displaying online with a future date.
Don't use the publish date as the event date. Save the event's date in a custom field in the format `yyyy-mm-dd`, and use a meta query to order events by that date. Also see `pre_get_posts` for ordering events correctly on archive pages without running a new query.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 0, "tags": "plugins, posts, date, scheduled posts" }
wp_redirect does not work I have a problem with `wp_redirect` which does seem to redirect. It's a full url that is on the current website. I need to put `exit();` after `wp_redirect` for it to redirect. Is this normal? Redirect is in an `init` action btw.
The only thing `wp_redirect()` is adding HTTP header to the current request. It doesn't prevent request from proceeding to further loading page and **must** be followed by exit statement to work correctly.
stackexchange-wordpress
{ "answer_score": 2, "question_score": 1, "tags": "redirect" }
The Best Way to always load the newest version of 3rd party code There is a class for plugins and themes that makes custom meta boxes easier to develop called cmb_Meta_Box from Custom-Metaboxes-and-Fields-for-WordPress at < and they update that class and code. I'm trying to make sure that if I use the latest version of this class/script in a plugin that if a user has an older version of it, it fails gracefully. So, for example, 1.1.0 has some new features, but if someone already has loaded 0.9.0 from another plugin that loaded before my plugin, what can I do? There is now a constant so I'm thinking I could warn the user on my admin pages, but if they're not technical they wouldn't know what to do with that warning. I hope this makes sense and some folks have ideas what I can do within WordPress to solve this possible issue. Thanks!
Short version — there isn't one. WordPress doesn't handle dependencies logic in any form. If library itself doesn't include any mechanism for it (which is exceedingly rare) — there isn't anything you can do. At best you can (and should) check if expected version of dependency is loaded (if it exposes version in some form or at least by location it's loaded from). In private sites this can be handled (via Composer for example), but there is no good solution for publicly distributed code.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "customization, metabox" }
Wordpress 3.9 Database Update Infinite Loop I recently updated my blog's Wordpress version to 3.9. After running the update I received this message upon trying to access the admin panel. > Database Update Required > > WordPress has been updated! Before we send you on your way, we have to update your database to the newest version. > > The update process may take a little while, so please be patient. I am presented then with a button " **Update Wordpress Database** ". When I click the button, after a short pause I am presented with the following message. > Update Complete > > Your WordPress database has been successfully updated! Great. Except that whenever I try to access the admin panel I am re-presented the first message asking me once again to update my database. Does anybody know of a way out of this infinite loop?
I had that on one of my sites recently (set to auto update core, so not sure if on 3.9 or one of 3.8.*). Flushing cache fixed it — `wp cache flush` via wp-cli, I imagine other ways would work just as well.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 8, "tags": "updates, upgrade" }
WordPress Terminology Options Vs. Settings What term should be used when defining a page in the admin menu that allows you to change a plugins options?
These two are pretty close, but relate to slightly different stages of the process. In purely technical terms WordPress has two different APIs — Options API and Settings API. Options API deals with saving and retrieving options from database. So its scope and scope of "options" in terminology is that of purely _storage_. Settings API deals with admin pages, forms, receiving/validating/sanitizing data, and finally using Options API to store it. So in terminology it refers more or less to level of admin interface and user interaction. Depending on nature of your plugin its page should be named either after its own name or after what plugin does. Then it should be nested appropriately in a level such as Settings or Appearance. Creating top level pages for the plugins is not uncommon, but is often considered overblown and annoying, especially so if the plugin/theme doesn't have _many_ things to put there.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 3, "tags": "plugin development" }
How to add custom rewrite rule to .htaccess? I want to add a custom rewrite rule to my `.htaccess` file using a function inside functions.php The rewrite rule I want to add is as follows: `RedirectMatch 301 ^/author/(.+)$ I know there is a WordPress function that adds a rewrite rule to the `.htaccess`: `$wp_rewrite->add_external_rule( 'mobile/([^/]+)$', 'mobile/index.php?action=$1' );` So, how can I use that to add my rewrite rule to `.htaccess`?
I found the solution on the Codex just after posting on the site and this is the code I was looking for: function my_htaccess_contents( $rules ) { $my_content = <<<EOD \n # BEGIN My Added Content # Protect wpconfig.php <Files wp-config.php> Order Allow,Deny Deny from all </Files> # END My Added Content\n EOD; return $my_content . $rules; } add_filter('mod_rewrite_rules', 'my_htaccess_contents');
stackexchange-wordpress
{ "answer_score": 8, "question_score": 7, "tags": "url rewriting, htaccess, rewrite rules" }
Problem converting tags to categories while having large number of tags I'm trying to convert some tags in my website to categories, via either Wordpress import tools or Taxonomy Converter plugin. In both cases, I get **Internal server Error** , when I try to query (load) the tags, because my website is having over 20,000 tags. Is there a manual or MySQL query method I can use for converting? Since my website can't just display the 20,000 tags in a single page for me to choose from.
Yes, there is a SQL-based method to do this. Just run this SQL (it will convert all tags to categories, if you want to convert only some of them, you have to add your conditions to `WHERE` clause): UPDATE wp_term_taxonomy SET taxonomy='category' WHERE taxonomy='post_tag' You can do this using `$wpdb`: $wpdb->query( "UPDATE $wpdb->term_taxonomy SET taxonomy='category' WHERE taxonomy='post_tag'" );
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "plugins" }
How to style the post previews/links without it affecting the main posts? I am a beginner but have spent a lot of time in trying to figure this out and to no avail. Using the developer tool in Chrome I have tried to find a particular class that's unique to the posts that show as previews in the homepage of a new WP site I am creating. But all of them are also applied to the _main post_ that arrives when you click the link to the post. So, what's the solution? I want to make the home page links look most like _featured posts_ that many sites have with a rectangular shape, with the posts main image as background or something.
As long as your theme is set up in the "normal" way, this is fairly easy. Lets take the markup for the Twenty Fourteen as an example. The type of page you are currently viewing creates a class on the `<body>`. So for a front-page blog (several articles) the `<body>` element contains the class "blog", A single post contains the class "single". (There are also classes like "archive" and "page" and so on.) So to format a single post, you add ".single" to your css. /* css */ .single .post { /* affects only single posts */ } .single .post h1 { /* affects only the <h1> of .single posts */ } To format the list of posts on a blog page, you add .blog. /* css */ .blog .post { /* this affects only posts on a .blog page */ } .blog .post h1 { /* this affects only the <h1> of posts on a .blog page */ } So keep using DevTools, but take a look at the classes of the `<body>` element.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "themes, css" }
What data does WordPress theme update pull If there is an update? I'd like to know what WordPress pulls to notify updates from the code. I'm currently facing an issue where my theme happens to have the same name as another theme which is already in the repository and it's notifying me that I'm currently using an older version of the theme. What's even worse, my theme gets replaced with that already existing theme when I click update. So it'll be great if I could just change a code or two to prevent this. I've tried changing the 'Theme Name' in style.css in the root folder (do I have to wait for this to update?) but it's not working. Note: I'm using my theme in MAMP (connected to the internet, of course). Does anyone know how to solve this? Thanks
Very typical and very annoying situation unfortunately. WordPress doesn't "pull" update information. Instead it _submits_ plugin and theme information to the API at wordpress.org, which responds with updates available. In practice matching of updates is loose and exact logic is not disclosed. Name matters a lot, folder name as well. Rest matters to some unknown degree. The closest to solution is filtering your theme's data out of HTTP requests to the API via `http_request_args` filter. There is old post on topic excluding your plugin or theme from update checks, but as of recently API requests had been changed to use JSON and code no longer applies as-is.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "themes" }
How to change page location in Wordpress I want to change my page location (link address). My blog page location is: I want to change blog page location ` to ` I want to create a option for user "Please select a page for home page". User selected page show as home page. For this reason I need to change page location. Thanks
Under "Settings" -> "Reading" in the wp-admin you (or other users) can set which page should be used as the home page.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 0, "tags": "menus, permalinks, homepage, paginate links" }
Get IDs of posts currently visible on archive This probably is a easy one for many. And also probably is already answered here, but I don't know how to search for it - so sorry I did search but not found anything. I like to get the contents of all posts currently visible on a archive page, during `wp_enqueue_scripts`. If I am right a good solution would be to just `get_post_field('post_content', $post_id)` for all of them. So what I need is just the IDs for the posts that will be displayed on the current archive page. Something that involved `new WP_Query` or `query_posts` I guess, but that a area I never really touched.
When the `wp_enqueue_scripts` action fires, the main query has already run and the posts are in the global `$wp_query`. We just need to grab the ID from each object in `$wp_query->posts`, the `wp_list_pluck` function makes that easy: function wpd_get_post_ids(){ if( is_archive() ){ global $wp_query; $post_ids = wp_list_pluck( $wp_query->posts, 'ID' ); // $post_ids now contains an array of IDs } } add_action( 'wp_enqueue_scripts', 'wpd_get_post_ids' );
stackexchange-wordpress
{ "answer_score": 4, "question_score": 2, "tags": "query, archives, post content" }
Why adding Categories does not auto refresh in Backend while using my custom theme? If I am using my own created custom theme, the Post Categories Page in admin panel is not getting updated automatically when I add a new Category. **To see the new category I have to reload the page Manually**. When I change to default themes it works as perfectly. So the problem is in my theme. I think I must have missed something in my functions file. Any idea what it can be??
If you are facing this problem you should check your themes function.php file. I had some error in that which caused this problem.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "categories, theme development, admin, wp admin, admin menu" }
Scheduling posts via sql I got 10k posts with dates that are in the future. I imported my posts as a draft cause it seems quicker. I have used phpmyadmin to set the status of the posts to future with this sql command: `UPDATE wp_posts SET post_status = 'future' WHERE post_status != 'static';` The problem is when I go look at my posts they all say missed schedule when the date hasn't gone past yet! Is there any fix to fix the scheduling?
The closest thing I can think of is a plug-in which will periodically take a draft and publish it for you. < Maybe that will help you. Update: above plugin has some issues so I wrote another one for this purpose. <
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, scheduled posts" }
Get custom taxonomy term url on archive page This is driving me crazy, so please help me guys with this. I'm trying to add a metatag to custom taxonomy ter archive page header which contains the url of the term archive page of a custom taxonomy. How to get the URL of the archive page when there's neither specified term nor the taxonomy itself.
I finally found the right answer for my question: First add this code: function get_tax_data($data){ if(!$data) return; global $wp_query; $term = $wp_query->get_queried_object(); if($data == 'title') return $term->name; if($data == 'description') return strip_tags($term->description); if($data == 'link') { $link = get_term_link($term); return $link; } } Now just add following to call the slug: `$the_tax = get_tax_data('link');`
stackexchange-wordpress
{ "answer_score": -2, "question_score": 1, "tags": "custom taxonomy, taxonomy" }
Define size for `get_post_gallery_images`, they seem to have been resized to 150x150 I'm using `get_post_gallery_images` and it's spitting images out as 150x150. It doesn't look like it takes a size parameter, so I assumed it would just spit out the largest image or preferably one of my defined sizes. 150x150 is too small though, is there somewhere I can declare what size gallery images I want? For instance I'm doing: <?php $gallery = get_post_gallery_images( $post ); foreach ($gallery as $img) { ?> <li><img src="<?php echo $img; ?>" /></li> <?php } ?> All of these images are coming out as 150x150, is there something I'm missing?
If you want `get_post_gallery_images` to give you _full_ size images, you can use the following: // Use full size gallery images for the next gallery shortcode: add_filter( 'shortcode_atts_gallery', 'wpse_141896_shortcode_atts_gallery' ); // Your code: $gallery = get_post_gallery_images( $post ); foreach ($gallery as $img) { ?> <li><img src="<?php echo $img; ?>" /></li> <?php } where /** * Set the size attribute to 'full' in the next gallery shortcode. */ function wpse_141896_shortcode_atts_gallery( $out ) { remove_filter( current_filter(), __FUNCTION__ ); $out['size'] = 'full'; return $out; } In this example we remove the filter after using it once, so it will not affect your other galleries. This way you don't have to include the `size="full"` attribute in your gallery shortcodes,
stackexchange-wordpress
{ "answer_score": 5, "question_score": 2, "tags": "gallery, images" }
add image size still doesn't work even after regenerating thumbnails I'm encountering this very frustrating problem where `add_image_size()` just doesn't seem to work at all (in fact, I've never seen it even work before). By not working, I mean not resizing / crop (if I take away my CSS width / height, the thumbnail will be the exact size in which I have uploaded it). I do have: 1. `add_theme_support( 'post-thumbnails' )` 2. `add_image_size( 'small-thumb', 60, 60, true )` 3. `the_post_thumbnail( 'small-thumb' )` 4. And most importantly, yes I've been regenerating my thumbnails close to 50 times now after changing the `add_image_size()` and it's not working. Now I do have a question related to this problem: Does CSS styling like `max-width`/ `max-height`/ `width` / `height` or anything effect WordPress' thumbnail functions? Anyone seem to know what else I can try to fix this? Thanks
There are a couple of things to check here. First, make sure that `add_theme_support( 'post-thumbnails' )` is loaded before `add_image_size( 'small-thumb', 60, 60, true )` You can always hook everything through a function to the `after_setup_theme` hook. I always add these in my theme setup function function wpse_setup_theme() { add_theme_support( 'post-thumbnails' ); add_image_size( 'small-thumb', 60, 60, true ); } add_action( 'after_setup_theme', 'wpse_setup_theme' ); Apart from that, everything should work if you call your post thumbnail correctly in the loop. On your question > Does CSS styling like max-width/ max-height/ width / height or anything effect WordPress' thumbnail functions? No, it doesn't. CSS only manipulate how a thumbnail is displayed on the front end
stackexchange-wordpress
{ "answer_score": 5, "question_score": 3, "tags": "themes, images, add theme support" }
Where the WordPress Core Translation is "actually" taking place? I'm a WordPress Core Bengali translator, currently translating and/or fixing existing translations of WordPress 3.8x Bengali in Translate.WordPress.org. Suddenly, yesterday I got an update notification in all my `WPLANG` '`bn_BD`' sites that, a new version of WordPress Bengali for WordPress 3.9 has come, so update your system. After the update I found a bluff update, because all the previous strings those were translated, got untranslated strings now. So, it's a bogus translation at all. As a Core translator, I jumped to the translate.wordpress.org's WordPress Projects, but found no such 3.9x translation project there. I wonder, **from Where** the official language release just happened, (as v3.9 is NOT a Dev. version now, it's a released one) if there's no such project's running!?
I maintain WordPress Bengali project and yesterday I pushed the 3.9 translation update from bn.wordpress.org. You are right, there are no 3.9.x branch there so it's pretty much not clear to me as well. Here's how it works: we should always translate from the Dev version. When a new release comes, there is a SVN revision for that WordPress release. We just refer to that revision and build a language pack from the development version (trunk). So whatever it's there, its been released as the new version. !enter image description here
stackexchange-wordpress
{ "answer_score": 2, "question_score": 2, "tags": "translation, wordpress version, wordpress.org" }
How to show months in wordpress archive page? I am a newbie to wordpress and have no knowledge of PHP. I want to show the months in my archive page, in this manner !enter image description here where, it shows the starting month when i my first post was made and continues to shows all months and year, till the current month of the year. I want the months to be hyperlinks of this manner ` based on each month and year. Please help me out, how to do it in PHP and wordpress.
Try to use this, <?php wp_get_archives( array( 'type' => 'monthly', 'limit' => 12 ) ); ?> Refer to the codex for further customisation,
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "archives" }
Use 'get' form action within a WordPress plugin admin page I am writing a WordPress plugin that has a dashboard URL like this... I have a datepicker box within the page that I use to select a date then click submit like this... <form action=" method="get"> <input type="text" class="mydatepicker" name="start_date" value=""/> <input type="submit" value="submit"> </form> I am expecting the page to reload with a URL like this... But instead i get this... What am I doing wrong?
Try to use this code, <form action=" method="get"> <input type="hidden" name="page" value="my-plugin.php" /> <input type="text" class="mydatepicker" name="start_date" value=""/> <input type="submit" value="submit"> </form> This will show the url like this... Check and let me know your comments, if it works
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "plugin development, admin" }
Is there a way to fire other functions from wp_insert_post I am creating a new post using the `wp_insert_post` function. Here's what that code looks like: $new_post = array( 'post_title' => $newtitle, 'post_status' => 'publish', 'post_content' => $repost[content], 'post_excerpt' => $repost[excerpt], 'post_author' => 1, 'post_type' => 'post', 'post_category' => explode(",",$catlist), ); wp_insert_post($new_post); The post is created fine, but I'd like to fire some other functions, such as Jetpack's social posting tools (Publicize.) Is there code to do that or would I be better in changing the post_status to draft and setting a future publishing date?
Use this code snippet to use another function, function my_function( $post_id ) { //Some code } add_action( 'save_post', 'my_function' ); This fires when a post is inserted.
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "wp insert post, plugin jetpack" }
How to make 3 boxes like this screenshot has? I am trying to create the 3 boxes that appear right below navigation and the email sign-up form. Is there a plugin to create something like that? Or what is a possible way to accomplish this sort of thing? !enter image description here Here is what I tried to do for posting the meta box, but it didn't show up. !enter image description here Also there is a calendar widget. But that isn't showing up either. Would you know why?
Your question is far too broad; you need to look at the CSS and HTML source and theme that site is based on to find out how that layout is done. Look at other free WP themes to find a similar layout. And learn how to use Firebug with Firefox, or use the developer tools in Chrome or Safari or IE.aspx) to see the CSS and HTML of that site and the site you're trying to develop.
stackexchange-wordpress
{ "answer_score": 1, "question_score": -5, "tags": "plugins" }
Automated Footer information Working on a theme and I'd like the copyright and title texts on the footer to be automated. It works but the tittle switches to the current page instead of the website's main title when you switch pages. How do I get it to stick to the website's main title or home page title. My line of code is as shown below. &copy;<?php echo date("Y"); ?> <?php the_title(); ?>
`the_title` is always the title of the current post. What you probably want is something like `wp_title` or `get_bloginfo` and `bloginfo('name');`. Take a look at your headers code to see exactly what your theme uses
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "theme development, themes, title, wp title" }
Using Wp_Query without the loop? I want to query for posts with a certain meta value. I would use the `WP_Query` but when in a loop (correct me if i am wrong.. I am learning wordpress; is it only when in loop? is the `the_post()` that sets the globals?), it changes the `global $post`. Is it possible to loop without setting up the global values? I just want to fetch some stuff in the posts, i don't want to use `the_content`, `the_title`, etc.. just raw rows of arrays? If I want to query `WP_Query` with meta fields conditions and expect and want only post, how do I get it? Do I still need to loop?
The query itself doesn't change globals, however you are correct that `the_post()` does. The most contained way to just retrieve posts (as array of results) is using `get_posts()` function, which is wrapper around `WP_Query` and takes same arguments.
stackexchange-wordpress
{ "answer_score": 3, "question_score": 0, "tags": "wp query, loop" }
Call to undefined function error after adding add_filter to wp-config I am getting Fatal error: Call to undefined function add_filter() in example.com/wp-config.php on line 20 after adding add_filter( 'auto_update_plugin', '__return_true' ); to wp-config.php My plugins.php file is present and add_filter() is defined inside of it. I just want to enable automatic updates for core, plugins and thems. What am I doing wrong?
There is a section that should look like this: defined( 'ABSPATH' ) || define( 'ABSPATH', __DIR__ . '/' ); require_once( ABSPATH . 'wp-settings.php' ); `add_filter()` is available **after** that, you are probably using it too early.
stackexchange-wordpress
{ "answer_score": 4, "question_score": 3, "tags": "filters, errors, wp config" }
Broken CSS after changing the site URL I have a self-hosted Wordpress blog on my home server. Previously I accessed it directly via its original IP address taken from DHCP, but now I have configured a static IP address for it. The problem is that now all the CSS is broken. I have updated my `wp-config.php` file adding the following two lines: define('WP_HOME',' define('WP_SITEURL',' and I have restarted apache, but the CSS is still broken. Is there some other configuration file that I should update?
For some reason, changing the URL from the GUI worked (after restoring the machine to the old IP address). Go figure.
stackexchange-wordpress
{ "answer_score": -1, "question_score": 4, "tags": "migration, ip" }
Get all fields inlcuding "ACF" (Advanced Custom Fields) columns in wp_query When retrieving posts with wp_query how do I make the loop contain the acf fields? $args = array( 'post_type' => $postTypes, 'posts_per_page' => $numPosts, 'offset' => $offset, 'meta_query' => $filterArgs ); $loop = new WP_Query( $args ); $postTypes is an array I have filled in advance containing "post", "page" etc. whatever I need. The loop will contain only the "standard" WP columns like post_content and so on.
The loop doesn't really contain anything. It does include methods in order to easily output your data such as `the_title()`, this is done when calling `the_post()` Then, within the loop you'll be able to use get_the_ID() and get_post_meta() to get your custom fields (including ACF ones). So if you have retrieved your desired posts from that query then you'll be able to do this: <?php while($loop->have_posts()) : $loop->the_post(); ?> <h2><?php the_title(); ?></h2> <?php the_content(); ?> <p>My Custom Field: <?php echo get_post_meta(get_the_ID(),'my-custom-field', true); ?> <?php endwhile; wp_reset_postdata(); ?> Hope that helps.
stackexchange-wordpress
{ "answer_score": 0, "question_score": 1, "tags": "wp query, loop, advanced custom fields" }
How to find meta entries with their posts missing via SQL? I'm looking to write an SQL query to do the following: Select all postmeta rows where the meta_value = a post id that does not exist. For example, postmeta meta_value may equal 235. Usually this would relate to a post (attachment) with 235 as an ID, however, it has been deleted. I want to find any postmeta rows like this and remove them. Hope this makes sense! Thanks in advance. EDIT: I've just found the NOT EXISTS function. I have a feeling something like this would work: SELECT m.* FROM wp_postmeta m WHERE m.meta_key = 'image' AND NOT EXISTS (SELECT * FROM wp_posts p WHERE m.meta_value = p.ID) Does this look right?
Of course, minutes after posting this I work it out. The following worked: SELECT m.* FROM wp_postmeta m WHERE m.meta_key = 'image' AND NOT EXISTS (SELECT * FROM wp_posts p WHERE m.meta_value = p.ID)
stackexchange-wordpress
{ "answer_score": 1, "question_score": 1, "tags": "mysql, sql" }
Twenty Fourteen theme and the page-templates folder I have to confess I'm struggling to see how the Wordpress Twenty Fourteen theme picks up templates put in the theme's `page-templates` folder. Previously I'd create new templates named `page-<slug>.php` in the theme's root folder, but not now. I've searched the code for mentions of `page-templates` and not found any where files are included; searched the WP source code too and found none. Can you explain how they're detected and picked up please?
The actual query for a Theme's page templates happens in `wp_get_theme()->get_page_templates()` (source), which in turn calls `get_files()` (source). The magic happens here: $files = (array) $this->get_files( 'php', 1 ); The args for `get_files()` are: function get_files( $type = null, $depth = 0, $search_parent = false ) {} So, when WordPress searches the Theme for PHP files, it passes a `$depth` argument of `1`, which means that it searches in subdirectories of the Theme root directory.
stackexchange-wordpress
{ "answer_score": 7, "question_score": 4, "tags": "theme twenty fourteen" }
How to add multiple values with add_query_arg? Let's suppose I am on this url of my site < And now someone clicks on a link generated with add_query_arg(). How can I make this link go to < Im trying to create a taxonomy filter and this is what I have: foreach ( $sub_terms as $st ) { echo '<a href="'. esc_url( add_query_arg( $taxonomy, $st->term_id ," ) ).'" class="subterm">'. $st->name .'</a>'; } Instead of appending my term id to the url, it just replaces cat with the new value: < I hope it's clear enough Thanks!
It's not "smart" enough to reason that you want to modify the value, not just set it to something. You'll need to: 1. retrieve the current value (`get_query_var()` probably) 2. change it as needed 3. use resulting value with `add_query_arg()`
stackexchange-wordpress
{ "answer_score": 0, "question_score": -1, "tags": "query" }
The loop does not show users I'm trying to show all post made ​​by the author. Code author.php <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php if( get_post_type() == 'post' ) {?> <?php } if( get_post_type() == 'post-type' ) {?> <?php } else; endwhile;?> <?php endif; ?> But just shows the post_type "post".
You need to add this code to the file `functions.php`. function custom_post_author_archive($query) { if ($query->is_author) $query->set( 'post_type', array('post-type', 'post') ); remove_action( 'pre_get_posts', 'custom_post_author_archive' ); } add_action('pre_get_posts', 'custom_post_author_archive');
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom post types, posts, loop, list authors" }
Get whole <li> linked with wp_list_pages I'm using wp_list_pages for my sidebar and it works fine to me, i just wanna add new feature which seems is not listed on codex or i don't know how to use it. $args = array( 'child_of' => 284, 'post_type' => 'page', 'sort_order' => 'ASC', 'sort_column' => 'post_date', 'title_li' => '', ); ?> <div id="#sidebar"> <ul> <?php wp_list_pages( $args ); ?> </ul> </div> and here is my CSS, as you see i get the ' * ' a background color with some padding. #sidebar li { font-size: .75em; padding: 10px; margin: 0 0 5px 0; background: #f18c21; color: white; So the think is, the only text on the li got the link, but what i would like to do is get the whole li section linked to the pages. Is there any way to do that?
As already said it's a question of the css-styles. Try something like #sidebar li a { display: block; margin: 0; padding: 5px 15px 5px 5px; text-align: left; } The `a` tag gets the padding, not the `li`-tag
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "customization, wp list pages, categories" }
Change the Permalink for wordpress attachment My attachments are currently rewritten from ` to ` using @Bainternet's answer here. $new_rules['images/(\d*)$'] = 'index.php?attachment_id=$matches[1]'; However, wordpress still refers to the link as the default ` Wordpress functions such as the_permalink, get_attachment_url, get_attachment_image_src, etc. all use the default format of ` I am able to access the image as intended if I manually type in the rewritten format ` How can I get wordpress to use my custom rewrite for the permalink especially on the admin page? **EDIT:** reworded question for specificity and correctness: How do I override `the_permalink` to use the format `/images/image-title` instead of `/?attachment_id=ID`? I can get image-title using `$post->post_title`. **EDIT #2:** For anyone reading this question in the future, I found it best to use `$post->post_name` for the link to insure uniqueness. `/images/post_title`
Your rule works with the attachment ID, so I'm not sure how you're using the title, but the answer is almost identical in either case. The filter you want is `attachment_link`: function wpd_attachment_link( $link, $post_id ){ $post = get_post( $post_id ); return home_url( '/images/' . $post->post_title ); } add_filter( 'attachment_link', 'wpd_attachment_link', 20, 2 ); Change `$post->post_title` to `$post->ID` to put the ID in the URL instead of title.
stackexchange-wordpress
{ "answer_score": 6, "question_score": 2, "tags": "attachments, seo, rewrite rules" }
Simple Wordpress function / plugin to redirect a site Is there a way to create a simple function that redirects every page of a site to another site? I've Googled around but all the plugins / functions that I've found are only really meant for redirecting individual pages and not entire sites. Any ideas?
While the plugin might solve your problem you could try something direct with WordPress API: add_action( 'template_redirect', 'wpse_142191_all_redirect' ); function wpse_142191_all_redirect() { if ( !is_user_logged_in() ) { wp_redirect( ' 301); exit; //always die or exit after redirect } } Be careful with it,this will redirect the whole site on the home page of other site. I added a condition, maybe you do not want to be redirect as a user of website.
stackexchange-wordpress
{ "answer_score": 2, "question_score": -1, "tags": "plugins, functions, redirect" }
How to list Custom Taxonomy I have a WordPress taxonomy, and I was wondering if there's anyway to list the taxonomy like: <ul id="portfolioFilter"> <li class="filter" data-filter="all">All</li> <li class="filter" data-filter="category1">Image Slider</li> <li class="filter" data-filter="category2">Youtube</li> <li class="filter" data-filter="category3">Vimeo</li> <li class="filter" data-filter="category4">Lightbox Photos</li> <li class="filter" data-filter="category5">Lightbox Video</li> </ul> Yup, there should not be any links, but Class filter in it data-filter with the term name. Is it possible? Thanks
Something like this should do the job: <?php $terms = get_terms('YOUR-TAXONOMY'); if ( $terms ) : ?> <ul id="portfolioFilter"> <li class="filter" data-filter="all">All</li> <?php foreach ( $terms as $term ): ?> <li class="filter" data-filter="<?php echo $term->slug; ?>"><?php echo esc_html($term->name); ?></li> <?php endforeach; ?> </ul> <?php endif; ?>
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "custom taxonomy, terms" }
Programmatically add posts from specific category to menu I am wanting to add individual posts to my primary menu programatically based on category I have used the wp_nav_menu_items filter previously to add pages to the menu but I am stuck when it comes to adding posts. add_filter( 'wp_nav_menu_items', 'fx_user_menu', 10, 2 ); function fx_user_menu( $items, $args ) { if ($args->theme_location == 'primary') { $myposts = get posts from specified category foreach ( $myposts as $post ) { $items .= '<li><a href="' . the_permalink() . '">' . the_title() . '</a></li>'; } } return $items; } Any ideas on how to get this working?
I'm not 100% sure if I get you right, but maybe this will solve your problem: add_filter( 'wp_nav_menu_items', 'fx_user_menu', 10, 2 ); function fx_user_menu( $items, $args ) { if ($args->theme_location == 'primary') { $myposts = get_posts( array( 'category' => <YOUR CATEGORY ID GOES HERE>, 'posts_per_page' => 5 ) ); foreach ( $myposts as $post ) { // you should not use the_title and the_permalink outside of The Loop - they won't work correctly $items .= '<li><a href="' . get_permalink($post->ID) . '">' . apply_filters('the_title', $post->post_title) . '</a></li>'; } } return $items; }
stackexchange-wordpress
{ "answer_score": 1, "question_score": 0, "tags": "posts, categories, menus" }