Tag Info

New answers tagged

1

You need to loop through the attachments within your post loop, replace the section of code you posted with this (put this together from some other code I found related to a similar problem, but couldn't test it): </BasicDetails> <?php $args = array( 'post_parent' => $post->ID, 'post_type' => 'attachment', ...


0

Slightly hard to follow you here, but from the file you posted there is a line: $excerpt = implode(" ",$excerpt)."..."; Change it to: $excerpt = implode(" ",$excerpt); Edit - Corrected line, should work now.


0

I had the same problem with neither the single-CUSTOM-TYPE.php nor the single.php being rendered after clicking the single-post-link.... only index.php instead of the correct file... What helped me was a simple change back to Standard Permalinks in "Settings" -> "Permalinks" and a restore back to "Name of the Post" (Beitragsname).... Maybe this might help ...


1

As stated in comments Most probably your posts per page setting for your site is less than 10 One have to remember, get_posts uses WP_Query. Any new instance of WP_Query and the main query (which also uses WP_Query) uses the value set for Blog pages show at most as default for the posts_per_page parameter when this parameter is not explicitly set by ...


0

You don't do that with your permalinks. You can do what you want in Wordpress Settings. Go to your Wordpress dashboard, 2. Click "Settings", 3. Click General. 4. In the "Site Address (URL)" Box remove the "blog" part like this --> "http://site.myurl.com/ NOTE: DON'T CHANGE THE WORDPRESS ADDRESS URL!!! Only change the Site Address Here is a screenshot ...


0

I just completed something like this (with great help from folks on this site). First, you need to add the rewrite endpoint to your functions: function wpa_read_endpoint(){ add_rewrite_endpoint( 'sub-url', EP_PERMALINK); } add_action( 'init', 'wpa_read_endpoint' ); Make sure to then go to the permalinks section of admin and save to refresh permalink ...


0

I found the solution. function add_rewrite_rules($rules) { $newrules = array('cpt-slug/([^/]+)/([^/]+)/?$' => 'index.php?name=$matches[1]&post_type=cpt_name&member_view=$matches[2]'); $rules = $newrules + $rules; return $rules; } You just need to change 'p' to 'name'


0

I'd say what you need to look deeper into is the Rewrite API and Endpoints, for starters see: Make WordPress: Rewrite endpoints API Codex: Rewrite API Codex: Rewrite API/add rewrite endpoint Additionally use the the search on here, because there are already similar Q&A's, which will definitely help you. Last note, doing such things manually ...


0

Not an answer (I'm not allowed to comment), but I'm wondering if you've ever figured this out? I'm also looking to allow visitors to see pending posts even though they don't necessarily have the proper credentials. Thanks.


0

To display published pages by default on pages link, simply paste this code snippet in your functions.php. You can then visit “All” tab to see full list of pages. // change page link to display published pages only function wcs_change_admin_page_link() { global $submenu; $submenu['edit.php?post_type=page'][5][2] = ...


0

I found the setting in WP -> Theme Panel -> Categories


1

You can make use of properties on elements. Have a look at the following concept and see if you can use it. You basically hide all "featured" images. Add a general class to the post titles which you want to use to show/hide images. Add a property to the post title element which holds the id of the image you want to show. Generated MarkUp: <img ...


1

Unless I am completely misunderstanding what you are trying to do, there is no need to move your site into a sub-folder. The easiest way to do what you want is to simply create your static page in normal html just as you want it to appear. Then add the following code to the very top of your page... <?php /* Template Name: Front Page */ ?> Then ...


2

I depends on your theme - they can be used for many things, but generally they are displaying in the list of the post, in the post itself (usually on the top of it). As well they are usually visible when sharing the link (for example in FB). But however, this is really pretty general question, you would have better to use google first (and maybe looking to ...


1

To accomplish this, you will need to know which is the last post on the page. There are a couple ways to achieve this, but I think the easiest way is to use pure php, the function end(). You are going to use this to get the last post in the loop. Once you have the last post in the loop, you can simply just compare the last post's ID with the current post ...


1

As your question does not state, I'm assuming that this is not your main query, but rather a stand alone that tells the visitor the most viewed page of the day. Therefore I believe that an instance of the WP_Query class is what you need. /** Query the posts to find the one with the most views from today */ $today = getdate(); $args = array( 'meta_key' ...


0

I think you only have to change '0', that is a string, by simply 0, that is a integer corresponding to the first place of the array of posts. I thik this is a good idea, maybe WordPress should do it by default ^^


0

add_action('future_to_pending', 'send_emails_on_new_event'); add_action('new_to_pending', 'send_emails_on_new_event'); add_action('draft_to_pending', 'send_emails_on_new_event'); add_action('auto-draft_to_pending', 'send_emails_on_new_event'); /** * Send emails on event publication * * @param WP_Post $post */ function send_emails_on_new_event($post) { ...


1

Since you've designated a specific page to be your Post Archive ( blog ) it no longer is a standard page; meaning is_page() will likely fail. Since your blog page is now more of an archive, it is automatically being returned because of your first conditional. is_singular() - Returns true when viewing a single page, post, or post type. So what you're ...


1

I am developing front-end content management screen and want to point all edit links to point to the front of the website. If you want to point all edit links to the FE, you should go for the get_edit_post_link filter solution (see Marko's answer). That will cover all cases where either the core or a plugin calls get_edit_post_link(). But if you want ...


6

Use get_edit_post_link filter. add_filter('get_edit_post_link', 'get_edit_post_link_178416', 99, 3); function get_edit_post_link_178416($link, $post_id, $context) { $scr = get_current_screen(); if ($scr->id == 'edit-post' && $context == 'display') { return 'http://google.com'; } else { return $link; } } You can ...


0

The only way I can see this working is by setting a couple of redirect rules in your .htaccess file. You'd have to manually redirect all your posts (that you want with that permalink structure) and prepend the /awesome URL part in front. Other than the aforementioned solution, which is a hack more than anything, I'm afraid that what you're looking for is ...


1

You have to change: 'post_type' => 'post', To: 'post_type' => 'your_custom_post_type_name', And a all the reference to standard post. Also, you should add the filters only for main query or you can end up with issues in secondary queries. Bellow an example code for gallery custom post type. I was trying to debug the code you posted (taken ...


0

Strange. Outside the loop, the_title() should give you the current page name, if you really are on a page, and not viewing a specific post. If it gives post title instead, it may mean that you are somehow inside a loop. But if that were true, wp_title shouldn't show "Blog". See if other options give the same result: //the_title(); single_post_title(); echo ...


2

By default add_action() only passes one parameter, not all three. Change your function to: add_action( 'transition_post_status', function ( $new_status, $old_status, $post ) { if( 'publish' == $new_status && 'publish' != $old_status ) { wp_die('STOP'); } }, 10, 3 ); Edited to add: The transition_post_status hook fires ...


2

Pro tip - don't custom query unless you need to (you don't). And never use the guid field. if ( is_singular() && $cats = get_the_category() ) $cat_id = $cats[0]->term_id; // Category ID for current post elseif ( is_category() ) $cat_id = get_queried_object_id(); // Category ID for current archive else $cat_id = 0; // No cats $posts = ...


2

To save: // Update and save the field so it can be used in our template if ( isset( $_POST['input_name'] ) ) { $data = sanitize_text_field( $_POST['input_name'] ); update_post_meta( $post_id, 'field_name', $data ); } To read: $data = get_post_meta( $post_id, 'field_name', true ); // With post object, a leaner, cleaner method: $data = ...


0

There is various approach you could take. All you need to do essentially is to get the author's role and put it in a statement of sort. For example, let's get the author role first by: // inside the loop $author_role = get_the_author_meta('roles', $post->post_author); Then just use do a if statement like: if ($author_role == 'contributor') { echo ...


2

You need to use the get_page_by_title function : $post = get_page_by_title( 'Post Title', OBJECT, 'player' );


0

If I were doing such a thing, I'd do something like the following Determine how to tell which posts people could potentially gain access to, perhaps via a custom field. Store user meta data holding the posts they have gained access to Write a quick class (or a couple of functions) to handle (a) gathering the list of posts they already have been granted to, ...


0

From your query (noted in the comments above), the page you are looking at believes that it is your home page (e.g. your blog). Notice in the wp_query object the following [found_posts] => 8 [is_home] => 1 is_home signifies that it believes that it is showing the home page. If your files are set up as you say, you should check your admin panel ...


1

Your problem is that you are checking for nonce and the nonce is stale. It is hard to make a specific comment about the need of using nonce in your case, but in general nonces should be used only for data submission not query.


0

It's late, but I found a solution after a pair of hours of search and I'm happy to share it. My solution works for any custom post type, so it won't be needed to specify the custom post type. So, if you are outside the loop, and you need to get the parent category name (or any parameter) of a custom post type, this is the way: $post_type = get_post_type(); ...


7

The post format taxonomy: The post format is a default taxonomy, registered with: register_taxonomy( 'post_format', 'post', array( 'public' => true, 'hierarchical' => false, 'labels' => array( 'name' => _x( 'Format', 'post format' ), 'singular_name' => _x( 'Format', ...


-1

You should rename your file archive-event.php instead of template-event.php as per the WordPress Theme Hierarchy. The template-event.php (template-customposttypename.php) file used for display the content of single events as the single.php working to display the content of post content. You can use your above code by using any page template also. I hope it ...


0

Something like this should work from your functions file as long as you use the correct conditional tag for your CPT archive: function exclude_single_post_cpt($query) { if (is_post_type_archive('event') && $query->is_main_query() && !is_admin() ) { $query->set('post__not_in', array(1646)); } } add_action('pre_get_posts', ...


0

To order taxonomy terms by ID, you have to set the orderby argument: $tax_terms = get_terms( 'portfolio', array( 'orderby' => 'id' ) ); See the get_terms Codex page for a complete list of arguments for the function. To order the posts by name (slug), set orderby to 'name' in your query arguments: $args = array( 'post_type' => $post_type, ...


1

EDIT From comments, it seems I've missed the actual purpose here Here is an update: There is no way to tell that or to know that. Every theme is unique and how a specific user uses a post format is also unique. If you read my answer, status is used to display statusses like twitter. So in content-status.php you would have just maybe the_excerpt(). ...


0

Post formats is an optional value added to WordPress posts which allows theme developers to define visual representation of a post. Theme developers can create themes with support for post formats. A number of post formats are available, however it is not possible for themes or plugins to introduce custom post formats. It is not necessary for theme ...


0

before your code, try and add: <?php if( is_home() && get_option( 'page_for_posts' ) ) { $posts_page = get_post( 'get_option( 'page_for_posts' ) ); echo apply_filters( 'the_content', $posts_page->post_content ); } ?> http://codex.wordpress.org/Function_Reference/is_home http://codex.wordpress.org/Option_Reference#Reading ...


1

With what you are asking, it is really difficult to come up with some performant easy way that is also reliable. As @birgire already stated, his solution is not reliable, but from tests, it seem to be the fastest clocking in at 2 db queries in about 0.015s average. From a quick discussion between @birgire and me in comments to his answer, I've decided to ...


0

Its an old question however would like to answer for other people Within ajax function hooked to wp_ajax do this. $url = wp_get_referer(); $post_id = url_to_postid( $url );


0

I think you have created a page template to display posts on a page. You can try once this code to display your post with all its tags. Paste this code on your page template and create a page from admin and select the templates which you have created. <?php $the_query = new WP_Query( 'showposts=5' ); while ($the_query -> have_posts()) : $the_query ...


0

First you've to know what you want to retrieve, you will have to find something identical for that group of post you want to retrieve. Use the following code to retrieve the post, where $args is the variable what contains the arguments to select the right post ids. $posts = get_posts($args); $terms=array(); foreach($posts as $post) { //Get all terms ...


0

You need to do it for each post, how to archive the post ids depends on how you get them (loop or list or ... ). wp_get_post_tags() only can be used for one id. therefore it needed to be called 3times one solution could be $id1=1; $id2=2; $id3=3; $tag_ids = array(); $tag_ids[] = wp_get_post_tags( $id1, array( 'fields' => 'name' ) ); $tag_ids[] = ...


1

Edited answer Thank you for you clarification above, and please give this a try - Note - This code assumes that you are using page.php, a variation of the page templage or some other custom template - it will not work on your index page (index.php). <div id="page-<?php the_ID(); ?>"> <?php if (have_posts()) : while (have_posts()) : ...


0

Another solution that seams to work is explained:here Adding the filter before the query: function filter_authors($groupby) { global $wpdb; $groupby = " {$wpdb->posts}.post_author"; return $groupby; } add_filter('posts_groupby','filter_authors'); And not forgetting to remove it afterwards: remove_filter('posts_groupby','filter_authors'); This ...


2

Out of curiosity, I played around with static SQL queries and this one seemed to work: SELECT r.post_author, r.ID, r.post_title FROM ( SELECT p.post_author, p.ID, p.post_title FROM wp_posts p INNER JOIN wp_term_relationships tr ON ( p.ID = tr.object_id ) WHERE p.post_date < '2015-02-05 00:00:00' AND p.ID NOT IN (10,20) ...


1

The post_date and post_date_gmt serves as the date that the post was created. For scheduled posts this will be the date on which the post is scheduled to be published. There is no reliable native method to determine the date when a scheduled post was added. For scheduled posts, you can try the post_modified or post_modified_gmt dates as this will correspond ...


0

This works fine for me when i test it. I did edit your code as you had a small error in the function name not matching. Also, you might want to add a conditional tag and wrap the shortcode in a div but otherwise it works. function adt_abovetitle($title){ //Return new title if called inside loop if ( in_the_loop() && is_singular('post') ...



Top 50 recent answers are included