Tag Info

New answers tagged

-2

Suppose you want to append blog before post in url than make sure that your blog page's slug name is blog . Then go to WP-admin-panel > settings > permalink and choose the last option "custom structure" and add following in it: /blog/%postname%/ and save changes. It will be only applied to your blog page, other page will not display blog as parent.


2

Your code will never get to the is_page_template() if statement because is_page_template() can only be true when is_page() is also true. It also looks like you've got some muddled elseif syntax (I think that's what you want?) and some generally inefficient code that repeats a lot. I'd do this: <?php if( is_page_template('right-sidebar.php') ) { // ...


1

/** * Get the author post count for a tax query. * * @link http://wordpress.stackexchange.com/q/159160/1685 * * @param array $tax_query * @return int */ function wpse_159160_get_author_posts_by_tax( $tax_query ) { global $wpdb; $where = get_posts_by_author_sql( 'post', true, get_post()->post_author ); $tax_query = new ...


6

For starters let's dive into what is 5 really. It is the post's ID. But what is ID in turn? It is value in the MySQL table row which identifies the specific post record. Issues with using IDs So first there are some conceptual problems with it. It's not content. It's not something user creates, manipulates, or (most of the time) aware of. WP is (by design) ...


6

This question is going to get some opinion based answers, but well, I'll give it a try. There are a couple of reasons why someone might've told you that, it would be great to know the context also. Upto version 3.4 or 3.5, that function only worked when the parameter was a var, that might be one of the reasons why someone told you that. I, myself, don't ...


1

Don't change the Post ID. Wordpress uses serialized data, and id's have deep linking within the database.


6

Prevent authors from publishing too short content: Here's one idea using a custom post status, for example short: /** * Register a custom 'short' post status * * @see http://wordpress.stackexchange.com/a/159044/26350 */ function wpse_short_post_status() { register_post_status( 'short', array( 'label' => _x( 'Short', ...


1

You can do this using a plugin. A couple of options are RSS Image Feed WP RSS Images


0

You can use cron-jobs and there's 2 ways you can do that: wp_schedule_event($timestamp, $recurrence, $hook, $args); http://codex.wordpress.org/Function_Reference/wp_schedule_event The action will trigger when someone visits your WordPress site, if the scheduled time has passed. Server cron job


0

Don't user custom fields to fix it, you should better try this: if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ){ $post_id = wp_insert_post( $my_post ); }


0

This is what I did on a recent site: $blog_page_object = get_queried_object(); $blog_page_title = $blog_page_object -> post_title; $blog_page_description = apply_filters('the_content', $blog_page_object -> post_content ); ?> <h1><?php echo( $blog_page_title ) ?></h1> <?php echo( $blog_page_description ) ?>


2

The correct way to register a taxonomy is to wait for the action registered_post_type, because that’s the only way to know that your post type actually exists. This action is fired when a post type was registered. Core post types are registered twice for reasons. You have to wait for the second call, because the rewrite object is not available earlier. If ...


0

From the register_taxonomy() codex page: Better be safe than sorry when registering custom taxonomies for custom post types. Use register_taxonomy_for_object_type() right after the function to interconnect them. Else you could run into minetraps where the post type isn't attached inside filter callback that run during parse_request or pre_get_posts. ...


0

Try this add_action( 'init', 'tag_synchro', 10 ); It might be the case that, when you set priority to 0 , your callback does not get called.


2

First of all I have to say that private posts already fit your needs, because logged in users with proper capability will see the posts in home page, archives, searches and so on. Proper capability is 'read_private_posts'. This cap is assigned by default to administrators and editors. So, your "member" users should have one of these 2 roles or maybe you ...


1

I've realised what the issue was... some of my posts were generated (for development purposes) using bulk creator which appears to not create a complete post! When I create a post manually using the WP backend my code works fine, thanks for the suggestions anyway guys!


1

You can just simply create a custom query with WP_Query. You just need to make sure if you are using a custom taxonomy or the build-in category. For reference, see: Is There a Difference Between Taxonomies and Categories? Here is an example for custom taxonomies (this can also be used for build-in categories, just change 'taxonomy' => ...


2

An example using wp_localize_script() which is a clean solution to insert JavaScript variables in the page. // Attaching to the wp_enqueue_scripts hook because of wp_localize_script() add_action( 'wp_enqueue_scripts', 'wpse158654_js_post_titles' ); function wpse158654_js_post_titles() { $args = array( 'posts_per_page' => 3, // Number of ...


2

You can use the WordPress function wp_get_recent_posts(), with required args. $output = array(); $args = array( 'numberposts' => 10, 'offset' => 0, 'category' => 0, 'orderby' => 'post_date', 'order' => 'DESC', 'include' => , 'exclude' => , 'meta_key' => , 'meta_value' =>, 'post_type' => 'post', 'post_status' => 'draft, ...


0

You could use get_posts to get the an array of posts objects, by default it returns the latest posts. You should iterate over the array and do what you need with the titles.


1

The reason why your check didn’t work is because is_singular() checks for post types, not for post IDs. is_singular( 'product' ) checks if the current post is of the type product, nothing else. The comparison 2295 === get_the_ID() does exactly what you need.


0

@toscho was correct. I replaced this: <?php if ( is_singular( '2295' ) ) : ?> With this: <?php if ( 2295 === get_the_ID() ) : ?>


0

If you call wp_list_categories, and add the parameter 'show_count'=> 1, it will return the number of posts in each category, inside parentheses. Regarding getting a date evaluation, you might want to use the date parameters in WP_Query.


1

I just ran into this with WooCommerce. I ended up passing the IDs I needed to a variable for safe keeping, and then hooking a function with extremely low priority. That worked fine. I figure woocommerce or what of my cleint's 8000000 plugins was overwriting post__in. add_filter('pre_get_posts', 'assign_ids', 1000);


0

function change_post_titles() { global $post, $title, $action, $current_screen; $title = "foo<br>bar"; $title = str_replace('<br>', ' ', $title); } add_action('admin_head', 'change_post_titles'); Use this this will give the result you want. Please check it let me know for any doubts.


0

If you need to modify the publish date for hundreds of posts then your best bet without a plugin or homemade solution is through a MySQL query.


4

The Automatic Sponsor Posts Injector: Here's one idea based on my answer for the question: How to show Y number of custom posts after every X normal posts? I hopefully made it a little bit more useful here on Github, but it may be refined much more (future work). The SponsorPostsInjector class will help you to automatically inject the sponsor posts into ...


1

You could modify it through the the_author filter: /** * Set the author name as the site title. */ ! is_admin() && add_filter( 'the_author', function( $author ) { return get_bloginfo( 'name' ); } ); where we change the author name to the site name on the frontend with the help of the get_bloginfo() function.


1

If you remove revisions, your blog is going to be identical for the user. Only in the backend, you won't have access anymore to your post history. You can also use plugins like https://wordpress.org/plugins/wp-optimize/ to do that. Ref: http://codex.wordpress.org/Post_Types#Revision


0

You could use a plugin like JSON API to create an endpoint on your WordPress installation and access it from your PHP site with Javascript. You'll still need to style it however.


0

I got the solution for this question. I need to apply there Isotope append method, when adding posts to the frontend. Here is the Isotope append method.


1

The second one is revision. It means the changes that you made, but didn't save. Wordpress saves that as revision post. There might be more than one revision post if you make more changes without updating the post. You don't need to worry about that. It's all in background and won't affect you in any way.


0

Depending on the exact functionality you should use different techniques. If you're allowing post data you would do post meta options (Get_post_meta). User data would be user_meta.. Most all the wordpress database actions are done by submitting through various types of WordPress functions. Sadly without knowing your goal I can't be more specific.


-1

For automatic posting to your facebook page, hopefully first you're using a page as opposed to a personal profile. Pages are publicly viewable. You'll probably also need to create an app for facebook as well. This plugin works for pages. https://wordpress.org/plugins/facebook-auto-publish/screenshots/


1

The problem was that I can't get wp_count of my custom post type. The result was that I got nothing. I found this solution $args = array( 'post_type' => 'orders' ); $count = new WP_Query( $args ); $orders = $count->found_posts +1; After this I insert my post


0

Go to Dashboard -> Appearance -> Widgets. You are looking for Archives widget. If your theme has built in sidebar, you'd just select the appropriate widget in that sidebar. To create a new sidebar in your theme, you need to use register_sidebar() in your theme's functions.php. To include a sidebar in your file, you'd use get_sidebar() in your ...


0

This seems to be what you are looking for Take into account that you probably will have to add a new file to your theme's directory. The rest is easy, just create a page and select the right template.


0

first of all you named your page template "Post Archive" not "All Posts"! and for a quick and easy solution check the link below: Creating an Archive Template


0

The code was working fine. My problem was that I forgot that I changed the default prefix of the database. Sorry guys for wasting your time. Have a good one


1

I suspect that PHP considers the value of $wpdb->get_row("SELECT * FROM wp_posts WHERE post_title = '" . $title . "'", 'ARRAY_A'); to be true no matter what (see also this). You'll have to count the number of rows that are returned Try something like this instead: $query = "SELECT COUNT(*) FROM wp_posts WHERE post_title = '$title'"; $count = ...


1

It looks like the xmlrpc_prepare_post filter is only applied to the output of the wp_getPost and wp_getRevision methods of the wp_xmlrpc_server class. It would be great if this code line: do_action( 'xmlrpc_call', 'wp.newPost' ); would be replaced with extra input arguments, for example: do_action( 'xmlrpc_call', 'wp.newPost', ..., $content_struct ); ...


1

For things like that a page is better option, because you can make use of custom page templates and also because pages are a better place for inner secondary queries. As example, if you want to use pagination for secondary queries, alongside next_posts_link() and previous_posts_link(), both those functions check if ( ! is_single() ) to display pagination ...


0

Here's one way to add post tags after the content on single posts only using the_content filter in a custom function from your functions file. Uses the_tags function tags_after_single_post_content($content) { if( is_singular('post') && is_main_query() ) { $tags = the_tags('<div class="entry-meta">Tagged with: ',' • ','</div><br ...


-1

Displays a list of tags with links to each one and a specific class for each tag: $tags = get_tags(); $html = '<div class="post_tags">'; foreach ( $tags as $tag ) { $tag_link = get_tag_link( $tag->term_id ); $html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>"; $html .= ...


0

The ../page/X structure ties to pagination, not to post names. I'm sure you could change them but I'm not sure how deep the effects of the change would be. Have you thought about an alternate solution? Name each post your chapter name Forward Chapter 1 Chapter 2 Add a plugin that adds previous / next navigation functionality each individual post. ...


0

The quickest way to achieve this effect is to position: absolute the background image. If your background image is in front of your text you can then use z-index to change the z-order. See https://developer.mozilla.org/en-US/docs/Web/CSS/position and https://developer.mozilla.org/en-US/docs/Web/CSS/z-index for reference on the 2 mentioned properties.


1

Your code doesn't make sense to me. The easiest way to do this is to use get_categories() to get all the categories, and use the exclude parameter to exclude the category that you don't need. You can then feed that back into a new WP_QUERY Example $categories = get_categories( 'exclude=ID_OF_CATEGORY') foreach ($categories as $category) { $new_query = ...


1

<?php if (have_posts()) : while (have_posts()) : the_post(); endwhile; else: _e('No blog found.', 'polymer'); endif; ?> if(have_post) condition is to check if the page contain post, while(have_posts) condition if there is more than one post display in loop, the_post() is used to display the post if(have_post) ...


2

You can try the the_content filter, to append/prepend text to the post content. Here's a simple example: add_filter( 'the_content', function( $content ) { if( is_single() && has_tag( 'follow-me-on-twitter' ) ) { $content .= '<div>Like my posts? Follow me on twitter!</div>'; } return $content; }, 99 ); where ...


0

What is referred to as a "template part" seems to fit exactly your need here. WP Template Part ref Simply write up the snippet that produces the message you would like to repeat in a php file and call it with <?php get_template_part( $slug, $name ); ?>



Top 50 recent answers are included